add scope to commands
This commit is contained in:
parent
ee642ae6e4
commit
63d8d74995
6 changed files with 42 additions and 4 deletions
|
@ -35,15 +35,43 @@ export default async (client: Client) => {
|
|||
command.data = command.data(client);
|
||||
client.commands.list.set(command.data.name, command);
|
||||
|
||||
return command.data.toJSON();
|
||||
return command;
|
||||
}),
|
||||
);
|
||||
}),
|
||||
)
|
||||
).flat(2);
|
||||
|
||||
// Send commands to Discord
|
||||
return await rest.put(Routes.applicationCommands(client.user?.id ?? ''), {
|
||||
body: commands,
|
||||
// Send guilds commands to Discord
|
||||
const scopedCommands = new Map<string, unknown[]>();
|
||||
|
||||
// Add commands to guild where the bot is
|
||||
const allowedGuilds = client.guilds.cache;
|
||||
|
||||
// Assign each commands to the guilds
|
||||
commands.filter((c) => c.scope().length > 0).forEach((c) => {
|
||||
c.scope().forEach((guild: string) => {
|
||||
if (allowedGuilds.get(guild) !== undefined) {
|
||||
const guildCommands = scopedCommands.get(guild);
|
||||
if (guildCommands === undefined) {
|
||||
scopedCommands.set(guild, [c.data.toJSON()]);
|
||||
} else {
|
||||
guildCommands.push(c.data.toJSON());
|
||||
scopedCommands.set(guild, guildCommands);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
scopedCommands
|
||||
.forEach(async (command, guild) => await rest.put(
|
||||
Routes.applicationGuildCommands(client.user?.id as string, guild), {
|
||||
body: command,
|
||||
}));
|
||||
|
||||
// Send global commands to Discord
|
||||
const globalCommands = commands.filter((c) => c.scope().length == 0);
|
||||
return await rest.put(Routes.applicationCommands(client.user?.id as string), {
|
||||
body: globalCommands.map((c) => c.data.toJSON()),
|
||||
});
|
||||
};
|
||||
|
|
|
@ -5,6 +5,8 @@ import { getLocale, getLocalizations } from '../../utils/locales';
|
|||
import { getFilename } from '../../utils/misc';
|
||||
|
||||
export default {
|
||||
scope: () => ['807244911350906920'],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
return new SlashCommandBuilder()
|
||||
|
|
|
@ -6,6 +6,8 @@ import { getFilename } from '../../utils/misc';
|
|||
import '../../modules/string';
|
||||
|
||||
export default {
|
||||
scope: () => [],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
return new SlashCommandBuilder()
|
||||
|
|
|
@ -4,6 +4,8 @@ import { getLocale, getLocalizations } from '../../utils/locales';
|
|||
import { getFilename } from '../../utils/misc';
|
||||
|
||||
export default {
|
||||
scope: () => [],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
return new SlashCommandBuilder()
|
||||
|
|
|
@ -5,6 +5,8 @@ import { getLocale, getLocalizations } from '../../utils/locales';
|
|||
import { getFilename } from '../../utils/misc';
|
||||
|
||||
export default {
|
||||
scope: () => ['441208120644075520'],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
return new SlashCommandBuilder()
|
||||
|
|
|
@ -7,6 +7,8 @@ import { getFilename } from '../../utils/misc';
|
|||
import { checkOwnershipReminder, deleteReminder, embedListReminders, getReminderInfo, newReminder } from '../../utils/reminder';
|
||||
|
||||
export default {
|
||||
scope: () => [],
|
||||
|
||||
data: (client: Client) => {
|
||||
const filename = getFilename(__filename);
|
||||
const loc_default = client.locales.get(client.config.default_lang);
|
||||
|
|
Loading…
Reference in a new issue