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);
|
command.data = command.data(client);
|
||||||
client.commands.list.set(command.data.name, command);
|
client.commands.list.set(command.data.name, command);
|
||||||
|
|
||||||
return command.data.toJSON();
|
return command;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
).flat(2);
|
).flat(2);
|
||||||
|
|
||||||
// Send commands to Discord
|
// Send guilds commands to Discord
|
||||||
return await rest.put(Routes.applicationCommands(client.user?.id ?? ''), {
|
const scopedCommands = new Map<string, unknown[]>();
|
||||||
body: commands,
|
|
||||||
|
// 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';
|
import { getFilename } from '../../utils/misc';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
scope: () => ['807244911350906920'],
|
||||||
|
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
return new SlashCommandBuilder()
|
return new SlashCommandBuilder()
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { getFilename } from '../../utils/misc';
|
||||||
import '../../modules/string';
|
import '../../modules/string';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
scope: () => [],
|
||||||
|
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
return new SlashCommandBuilder()
|
return new SlashCommandBuilder()
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { getLocale, getLocalizations } from '../../utils/locales';
|
||||||
import { getFilename } from '../../utils/misc';
|
import { getFilename } from '../../utils/misc';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
scope: () => [],
|
||||||
|
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
return new SlashCommandBuilder()
|
return new SlashCommandBuilder()
|
||||||
|
|
|
@ -5,6 +5,8 @@ import { getLocale, getLocalizations } from '../../utils/locales';
|
||||||
import { getFilename } from '../../utils/misc';
|
import { getFilename } from '../../utils/misc';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
scope: () => ['441208120644075520'],
|
||||||
|
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
return new SlashCommandBuilder()
|
return new SlashCommandBuilder()
|
||||||
|
|
|
@ -7,6 +7,8 @@ import { getFilename } from '../../utils/misc';
|
||||||
import { checkOwnershipReminder, deleteReminder, embedListReminders, getReminderInfo, newReminder } from '../../utils/reminder';
|
import { checkOwnershipReminder, deleteReminder, embedListReminders, getReminderInfo, newReminder } from '../../utils/reminder';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
scope: () => [],
|
||||||
|
|
||||||
data: (client: Client) => {
|
data: (client: Client) => {
|
||||||
const filename = getFilename(__filename);
|
const filename = getFilename(__filename);
|
||||||
const loc_default = client.locales.get(client.config.default_lang);
|
const loc_default = client.locales.get(client.config.default_lang);
|
||||||
|
|
Loading…
Reference in a new issue