51
loading...
This website collects cookies to deliver better user experience
!ping
. Again this can be constructed into anything you want. Like you say Hey
and bot will say 'Hola' you get the idea right.New Application
button.
Tutorial-Bot
and hit Create
Bot
and click on Add Bot
.
Yes, do it
OAuth2
section and copy Application Id
<app-id>
with the application id
you copied into the following link :https://discord.com/api/oauth2/authorize?client_id=<app-id>&permissions=8&scope=bot
npm init -y
git init
index.js
, config.json
,.env
, .gitignore
Now create a folder Commands
and add pong.js
& command.js
file in it. Now your file/folder structure should look something like this (only pong.js
and command.js
are in Commands
folder)
Now add the code to the respective files as heading
Add the following code
const Discord = require('discord.js');
const client = new Discord.Client();
const env = require('dotenv').config();
const command = require('./Commands/command.js');
const pong = require('./Commands/pong.js');
console.log('Yay your bot is live');
client.on('ready', () => {
console.log(`Bot is currently running on version v${require('./package.json').version}`);
command(client,'ping', message => {
pong(message);
});
});
client.login(process.env.BOTTOKEN);
const {prefix} = require('../config.json');
module.exports = (client, aliases, callback) => {
if(typeof aliases === 'string'){
aliases = [aliases];
}
client.on('message', message => {
const {content} = message;
aliases.forEach(alias => {
const command = `${prefix}${alias}`
if(content.startsWith(`${command}`) || content === command){
console.log(`Running the command ${command}`)
callback(message);
}
});
});
};
module.exports = async function (message) {
message.channel.send('Pong!');
}
{
"prefix": "!"
}
/node_modules/
.env
Bot
and then copy the token as shown in the below imageBOTTOKEN=XXXXXXXXXX
npm install discord.js
npm install dotenv
node index.js
!ping
you should receive pong in response like below.
index.js
which will be the entry point point of the application/bot. then we authenticatied it using client.login('process.env.BOTTOKEN')
and we checked if your application was online.command.js
if it was then we will run the operation present in pong.js
file.index.js
and write at what keyword would you like it to get triggered. and that's it.