Created the command type `per-guild` these commands are registered when the bot enters a new guild, different of the global type, they can have permissions edited (the permissions system need to be developed yet). `guild` commands will be registered just in the development guild (probably the purpose of them need to be rethought). The reload command became adapted to be compatible with the command type system. When a command is reloaded, it's on all other guilds.
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
const { Routes } = require('discord-api-types/v9');
|
|
|
|
const { commandsData, commands, rest } = require('../../index');
|
|
const console = require('../../functions/meta/console');
|
|
|
|
module.exports = {
|
|
name: 'ready',
|
|
async execute(client) {
|
|
|
|
await client.application?.fetch();
|
|
|
|
const guilds = await client.guilds.cache.map(guild => guild.id);
|
|
|
|
console.debug(guilds);
|
|
|
|
for (const command of commands) {
|
|
|
|
if(!command.properties.type.includes('guild')) continue;
|
|
|
|
const clientCommand = (await client.guilds.cache.get(process.env.DEV_GUILD)?.commands.fetch()).find(c => c.name === command.data.name);
|
|
|
|
if(command.permissions) {
|
|
await clientCommand.permissions.set({ id: clientCommand.id, permissions: command.permissions });
|
|
}
|
|
|
|
command.id = clientCommand.id;
|
|
command.name = clientCommand.name;
|
|
}
|
|
|
|
for (const guild of guilds) {
|
|
|
|
if(guild.id == process.env.DEV_GUILD) continue;
|
|
|
|
try {
|
|
await rest.put(
|
|
Routes.applicationGuildCommands(process.env.CLIENT, guild), {
|
|
body: commandsData.perGuild,
|
|
},
|
|
);
|
|
}
|
|
catch (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
}
|
|
|
|
console.info('Guild Commands:');
|
|
console.table(commands);
|
|
|
|
console.info('Bot configurations:');
|
|
console.table({
|
|
'Owner Id': process.env.OWNER,
|
|
'Development Guild Id': process.env.DEV_GUILD,
|
|
'Client Id': process.env.CLIENT,
|
|
});
|
|
|
|
console.info('BOT READY');
|
|
|
|
},
|
|
}; |