bot-discord.js-template/index.js

39 lines
1.5 KiB
JavaScript

// Import bot configuration
const config = require('./config.json');
// Import Client and Intents objects from discord.js
const { Client, Intents } = require('discord.js');
// Setting up bot intents flags
const client = new Client(
{
intents: [
Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_TYPING, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS
],
partials: [
'CHANNEL', // Allow bot to read DM message
]
}
);
// Define once event listener (happen one time) to indicate when bot is ready.
client.once('ready', () => {
console.log('\nCongratulations, your discord bot is now online !\nYou are using "bot-discord.js-template" a template developed by EndMove.');
});
// Define event listener to reply ping by pong.
client.on('messageCreate', message => {
console.log(`[${config.name}]: the message (${message.content}) has been sent by (${message.author.username}).`);
if (message.content === 'ping') {
message.reply('pong !').then(reply => {
console.log(`[${config.name}]: The bot answered to (${message.author.username}).`);
reply.react('😄');
message.react('👌');
if (message.channel.type !== 'DM') message.author.send({content: `Hello, I just answered your "ping", hope you will appreciate my answer.`});
});
}
})
// Authenticate the bot -> turn on
client.login(config.token);