Created
August 28, 2022 10:22
-
-
Save mikkipastel/06f49afde4a01a2c4b52f830478c358c to your computer and use it in GitHub Desktop.
default discord command bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//include library | |
const { Client, GatewayIntentBits, SlashCommandBuilder, Routes } = require('discord.js'); | |
const { REST } = require('@discordjs/rest'); | |
const client = new Client({ intents: [GatewayIntentBits.Guilds] }); | |
// map command list | |
const commands = [ | |
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!') | |
].map(command => command.toJSON()); | |
// regsiter command | |
const rest = new REST({ version: '10' }).setToken(process.env.token); | |
rest.put(Routes.applicationGuildCommands(process.env.clientId, process.env.guildId), { body: commands }) | |
.then(() => console.log('Successfully registered application commands.')) | |
.catch(console.error); | |
//reply command | |
client.once('ready', () => { | |
console.log('Ready!'); | |
}); | |
client.on('interactionCreate', async interaction => { | |
if (!interaction.isChatInputCommand()) return; | |
const { commandName } = interaction; | |
if (commandName === 'ping') { | |
await interaction.reply('Pong!'); | |
} | |
}); | |
client.login(process.env.token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment