I'm programming my first Discord bot and I programmed it to output something to the console whenever it starts up, or in other words whenever client.on("ready")
is called. However, I can't get it to actually fire and I don't know why. I have all Node dependencies installed, the bot is in the server and is able to send messages, and the first few lines of the program run fine.
What is the problem?
Here is the source:
console.log("Launching bot...\n");
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
client.on("ready", () => {
console.log(`Bot has started, with
${client.users.size} users, in
${client.channels.size} channels of
${client.guilds.size} guilds.`);
client.user.setActivity(`Serving
${client.guilds.size} servers`);
});
client.on("message", async message => {
if(message.authot.bot) return;
if(message.content.indexOf(config.prefix) !== 0)
return;
const args =
message.content
.slice(config.prefix.length).trim().split(/ +
/g);
const mand = args.shift().toLowerCase();
if(mand === "ping") {
let m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp -
message.createdTimestamp}ms. API Latency is
${Math.round(client.ping)}ms`);
}
});
I'm programming my first Discord bot and I programmed it to output something to the console whenever it starts up, or in other words whenever client.on("ready")
is called. However, I can't get it to actually fire and I don't know why. I have all Node dependencies installed, the bot is in the server and is able to send messages, and the first few lines of the program run fine.
What is the problem?
Here is the source:
console.log("Launching bot...\n");
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
client.on("ready", () => {
console.log(`Bot has started, with
${client.users.size} users, in
${client.channels.size} channels of
${client.guilds.size} guilds.`);
client.user.setActivity(`Serving
${client.guilds.size} servers`);
});
client.on("message", async message => {
if(message.authot.bot) return;
if(message.content.indexOf(config.prefix) !== 0)
return;
const args =
message.content
.slice(config.prefix.length).trim().split(/ +
/g);
const mand = args.shift().toLowerCase();
if(mand === "ping") {
let m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp -
message.createdTimestamp}ms. API Latency is
${Math.round(client.ping)}ms`);
}
});
Share
Improve this question
edited Sep 4, 2018 at 17:58
Federico Grandi
6,7865 gold badges33 silver badges51 bronze badges
asked Sep 4, 2018 at 2:45
hyphxnatedhyphxnated
631 gold badge1 silver badge5 bronze badges
2
- 1 Did you correctly set the bot up in Discord? How are you running the script? – GMaiolo Commented Sep 4, 2018 at 2:58
- yeah i'm pretty sure i did it's in the discord server. and i'm running it with node from mand line – hyphxnated Commented Sep 4, 2018 at 4:43
1 Answer
Reset to default 3You forgot to use the .login
method for your client, that's the reason why your ready
event doesn't get triggered!
Here is the updated code, you just have to insert your top secret key from https://discordapp./developers/applications/
console.log("Launching bot...\n");
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
client.on("ready", () => {
console.log(`Bot has started, with
${client.users.size} users, in
${client.channels.size} channels of
${client.guilds.size} guilds.`);
client.user.setActivity(`Serving
${client.guilds.size} servers`);
});
client.on("message", async message => {
if(message.authot.bot) return;
if(message.content.indexOf(config.prefix) !== 0)
return;
const args =
message.content
.slice(config.prefix.length).trim().split(/ +
/g);
const mand = args.shift().toLowerCase();
if(mand === "ping") {
let m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp -
message.createdTimestamp}ms. API Latency is
${Math.round(client.ping)}ms`);
}
});
client.login("YOUR TOP SECRET KEY")