Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Latest commit

 

History

History
97 lines (84 loc) · 3.45 KB

README.md

File metadata and controls

97 lines (84 loc) · 3.45 KB

How do I test it?

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.

What's included?

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.

How do I add commands?

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.

Useful code snippets

For embeds

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)

Using VC

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)

Common Objects & Lines

Lines

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();

Objects

The message's author:

message.author

The bot's user object:

client.user