mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-12-23 01:13:17 +00:00
Handle application commands better in commands.ts
This commit is contained in:
parent
0f33298859
commit
080e070f19
@ -1,4 +1,4 @@
|
|||||||
import { Snowflake } from "discord.js";
|
import { ApplicationCommand, ApplicationCommandManager, BaseGuild, Guild, GuildApplicationCommandManager, OAuth2Guild, Snowflake } from "discord.js";
|
||||||
import RadioClient from "../Client";
|
import RadioClient from "../Client";
|
||||||
import help from "./commands/help";
|
import help from "./commands/help";
|
||||||
import invite from "./commands/invite";
|
import invite from "./commands/invite";
|
||||||
@ -20,51 +20,40 @@ export interface command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function commands(client: RadioClient) {
|
export default async function commands(client: RadioClient) {
|
||||||
const commands : command[] = [ help, invite, list, maintenance, next, play, prev, statistics, status, stop ];
|
const commands1 : command[] = [ help, invite, list, maintenance, next, play, prev, statistics, status, stop ];
|
||||||
|
const commands2 = await client.application?.commands.fetch();
|
||||||
|
|
||||||
for(const command of commands){
|
for(const command of commands1){
|
||||||
client.commands.set(command.name, command);
|
client.commands.set(command.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!client.application) return;
|
|
||||||
client.funcs.logger('Application Commands', 'Started refreshing application (/) commands.');
|
client.funcs.logger('Application Commands', 'Started refreshing application (/) commands.');
|
||||||
if(client.config.devMode){
|
if(commands1){
|
||||||
client.application.commands.set([]);
|
for(const command of commands1){
|
||||||
for(const command of commands){
|
await client.application?.commands.create({
|
||||||
let guilds = await client.guilds.fetch();
|
|
||||||
guilds.forEach(async (guild: { id: Snowflake; name: string; }) => {
|
|
||||||
try {
|
|
||||||
if(!client.application) return;
|
|
||||||
await client.application.commands.create({
|
|
||||||
name: command.name,
|
|
||||||
description: command.description,
|
|
||||||
options: command.options || []
|
|
||||||
}, guild.id);
|
|
||||||
client.funcs.logger('Application Commands', 'Guild: ' + guild.id + " (" + guild.name + ") \n" + 'Command: ' + command.name);
|
|
||||||
} catch(DiscordAPIError) {
|
|
||||||
client.funcs.logger('Application Commands', 'Guild: ' + guild.id + " (" + guild.name + ") [FAILED] \n" + 'Command: ' + command.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(const command of commands){
|
|
||||||
await client.application.commands.create({
|
|
||||||
name: command.name,
|
name: command.name,
|
||||||
description: command.description,
|
description: command.description,
|
||||||
options: command.options || []
|
options: command.options || []
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client.funcs.logger('Application Commands', 'Command: ' + command.name);
|
if(commands2){
|
||||||
|
commands2.forEach(async command2 => {
|
||||||
|
if(commands1.findIndex((command1) => command1.name == command2.name) == -1){
|
||||||
|
await client.application?.commands.delete(command2.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let guilds = await client.guilds.fetch();
|
let guilds = await client.guilds.fetch();
|
||||||
guilds.forEach(async (guild: { id: Snowflake; }) => {
|
guilds.forEach(async (guild: Guild | OAuth2Guild) => {
|
||||||
try {
|
try {
|
||||||
if(!client.application) return;
|
if(!client.application) return;
|
||||||
await client.application.commands.set([], guild.id);
|
await client.application.commands.set([], guild.id);
|
||||||
} catch (DiscordAPIError){
|
} catch (DiscordAPIError){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
client.funcs.logger('Application Commands', 'Successfully reloaded application (/) commands.' + "\n");
|
client.funcs.logger('Application Commands', 'Successfully reloaded application (/) commands.' + "\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user