Instead of running node .
to start the bot, take advantage of the nodemon
dev dependancy that you installed while running npm i
. By using nodemon .
to run the bot, instead of node .
nodemon will restart the bot every time you save changes, making developement that much easier and quicker. For more information on nodemon, click here.
I have included 3 basic commands for this bot.
help
returns a list of commands and their descriptions. You can add more to the base help command under line 13. If given arguments, the command looks for the command name given and grabs the description for it.
google
returns a google search query based off the arguments given. If no arguments are given, it brings you to google's main page.
eval
evaluates code for you. This command is set to only work for administrators as it can be easily exploited.
You can add commands easly using the following template in a new CommandName.js
folder in this directory:
const Discord = require('discord.js')
module.exports.run = async (client, message, args) => {
// do stuff
return
}
module.exports.help = {
name: "This is the command name", // the command's name
description: "This is a description" // the command's description
}
The command name is used for how the command is called and both the name and description are used by the help
command.
For more information on discord.js, visit the guide here.
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
(from here)
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
} else {
return message.reply("please first join a voice channel.");
}
const dispatcher = connection.play('audio.mp3');
dispatcher.on('start', () => {
console.log('audio.mp3 is now playing!');
});
dispatcher.on('finish', () => {
console.log('audio.mp3 has finished playing!');
});
(from here)
To send a message in the channel the message came from:
message.channel.send("This is a message.");
To reply to a message:
message.reply("this is a reply.")
To delete the reciving message:
message.delete();
The message's author:
message.author
The bot's user object:
client.user