Change updateGuild to refresh guild and make it actually work
This commit is contained in:
parent
c04b6ffc11
commit
f5b18513d2
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"build": "rm -rf ./dist && tsc -p .",
|
||||
"start": "node ./dist/main.js",
|
||||
"refresh": "node ./dist/scripts/updateGuild.js",
|
||||
"refresh": "node ./dist/scripts/refreshGuild.js",
|
||||
"prettier": "if prettier -v >/dev/null 2>&1; then prettier . --write; else npx prettier . --write; fi",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
|
|
@ -29,7 +29,7 @@ const commandsData = Object.values(commands).map(command =>
|
|||
command.data.toJSON()
|
||||
);
|
||||
|
||||
const rest = new REST({ version: "9" }).setToken(BOT_TOKEN);
|
||||
export const rest = new REST({ version: "9" }).setToken(BOT_TOKEN);
|
||||
|
||||
export async function deployCommands({ guildId }: DeployCommandsProps) {
|
||||
try {
|
||||
|
|
|
@ -16,21 +16,31 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Events } from "discord.js";
|
||||
import { BotClient, deployCommands } from "../bot";
|
||||
import { Events, Routes } from "discord.js";
|
||||
import { BOT_ID, BotClient, deployCommands, rest } from "../bot";
|
||||
|
||||
if (process.argv.length < 3 || !process.argv[2]) {
|
||||
console.log("You need to specify the guild ID to refresh.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [, , guildId] = process.argv;
|
||||
|
||||
BotClient.on(Events.ClientReady, () => {
|
||||
try {
|
||||
BotClient.fetchGuildPreview(process.argv[2])
|
||||
.then(({ id, name }) => {
|
||||
deployCommands({ guildId: id });
|
||||
console.log(`Updated (/) commands for "${name}".`);
|
||||
process.exit(0);
|
||||
rest
|
||||
.put(Routes.applicationGuildCommands(BOT_ID, guildId), { body: [] })
|
||||
.then(() => {
|
||||
console.log("Deleted (/) commands.");
|
||||
deployCommands({ guildId: guildId })
|
||||
.then(() => {
|
||||
console.log("Successfully reloaded (/) commands.");
|
||||
process.exit(0);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("An error occurred refreshing (/) commands:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("An error occured refreshing (/) commands:", err);
|
Loading…
Reference in a new issue