Creating a Bot Account — discord.py 1.3.0a documentation

Creating a Bot Account — discord.py 1.3.0a documentation

We also recommend putting in the nodemon tool. It’s a command line app that monitors your bot’s code and restarts robotically on adjustments. you may deploy it by means of going for walks the following command:

npm i -g nodemon

You’ll Discord bot a text editor. you could simply use notepad, but we recommend either Atom or VSC.

right here’s our “hi there global”:

const Discord = require(‘discord.js’);

const patron = new Discord.customer();

consumer.on(‘equipped’, () =>

console.log(`Logged in as $consumer.user.tag!`);

);

client.on(‘message’, msg =>

if (msg.content material === ‘ping’)

msg.respond(‘pong’);

);

patron.login(‘token’);

This code is taken from the discord.js example. let’s damage it down

The primary  strains are to configure the customer. Line one imports the module into an item called “Discord,” and line  initializes the purchaser object.The purchaser.on(‘equipped’) block will fireplace whilst the bot starts offevolved up. here, it’s just configured to log its name to the terminal.

The customer.on(‘message’) block will fireplace everytime a new message is posted to any channel. Of path, you’ll want to test the message content, and that’s what the if block does. If the message simply says “ping,” then it’s going to respond with “Pong!”

The ultimate line logs in with the token from the bot portal. glaringly, the token in the screenshot right here is fake. Don’t ever submit your token at the net.copy this code, paste to your token at the lowest, and shop it as index.js in a committed folder.

Leave a Reply

Your email address will not be published. Required fields are marked *