diff --git a/examples/npm/discord/index.js b/examples/npm/discord/index.js index 928a77f..cd57755 100644 --- a/examples/npm/discord/index.js +++ b/examples/npm/discord/index.js @@ -1,24 +1,25 @@ import { Client, GatewayIntentBits, Routes, SlashCommandBuilder } from 'discord.js'; -const DISCORD_TOKEN = process.env.DISCORD_TOKEN; const CLIENT_ID = process.env.DISCORD_CLIENT_ID; +const GUILD_ID = process.env.DISCORD_GUILD_ID; +const DISCORD_TOKEN = process.env.DISCORD_TOKEN; const commands = [ - new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'), - new SlashCommandBuilder().setName('hello').setDescription('Says hello') + new SlashCommandBuilder().setName('version').setDescription('show ant version'), + new SlashCommandBuilder().setName('github').setDescription('link to ant github') ].map(c => c.toJSON()); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); -client.once('ready', async () => { - await client.rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); - console.log(`Logged in as ${client.user.tag}`); +client.once('clientReady', async () => { + await client.rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands }); + console.log(`logged in as ${client.user.tag}`); }); client.on('interactionCreate', async interaction => { if (!interaction.isChatInputCommand()) return; - if (interaction.commandName === 'ping') await interaction.reply('pong!'); - else if (interaction.commandName === 'hello') await interaction.reply(`hi ${interaction.user.username}!`); + if (interaction.commandName === 'version') await interaction.reply(`ant ${Ant.version}`); + else if (interaction.commandName === 'github') await interaction.reply(`https://github.com/themackabu/ant`); }); client.login(DISCORD_TOKEN);