Skip to content

Commit

Permalink
Fixed commands on join
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo0111 committed Apr 18, 2022
1 parent fe8c391 commit 88c1ac9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bot.config = require('./config.json');
bot.data = require('./data.json');
bot.logger = new Logger(console.log);

const commands = [new SlashCommandBuilder()
bot.commands = [new SlashCommandBuilder()
.setName('version')
.setDescription('Retrieves the latest version of a plugin')
.addStringOption(option =>
Expand All @@ -38,7 +38,7 @@ const commands = [new SlashCommandBuilder()
.setRequired(true)).toJSON()]

if (bot.config.public) {
commands.push(new SlashCommandBuilder()
bot.commands.push(new SlashCommandBuilder()
.setName('add')
.setDescription('Adds a plugin to the list to check')
.addIntegerOption(option =>
Expand All @@ -52,7 +52,7 @@ if (bot.config.public) {
.addChannelType(ChannelType.GuildText)).toJSON());
}

const rest = new REST({ version: '9' }).setToken(bot.config.token);
bot.rest = new REST({ version: '9' }).setToken(bot.config.token);

bot.on('ready',() => {
bot.logger.info(`Logged in as ${bot.user.tag}.`)
Expand All @@ -69,9 +69,9 @@ bot.on('ready',() => {
(async () => {
bot.guilds.cache.forEach(guild => {
try {
rest.put(
bot.rest.put(
Routes.applicationGuildCommands(bot.user.id, guild.id),
{ body: commands },
{ body: bot.commands },
);
} catch (error) {
bot.logger.error("Error while trying to load commands. Are you missing the Commands permission?");
Expand Down
14 changes: 14 additions & 0 deletions modules/join.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { Routes } = require('discord-api-types/v9');

module.exports = async (client) => {
client.on('guildCreate', async guild => {
try {
client.rest.put(
Routes.applicationGuildCommands(client.user.id, guild.id),
{ body: client.commands },
);
} catch (error) {
client.logger.error("Error while trying to load commands. Are you missing the Commands permission?");
}
});
}

0 comments on commit 88c1ac9

Please sign in to comment.