Send message to channels - discord.js #5196
-
const Discord = require("discord.js");
const client = new Discord.Client();
const token = "token";
client.login(token);
client.channels.cache.get("channel_id").send("Hello!"); I can not see the send method even in the code suggestion. Channel is not cached maybe. Is there any other way to send messages to a specific channel? |
Beta Was this translation helpful? Give feedback.
Answered by
Androz2091
Jan 9, 2021
Replies: 1 comment 1 reply
-
Hello @rahultrivedi180, you have to wait for the client to be ready and send the message. You can use the following code: const Discord = require("discord.js");
const client = new Discord.Client();
const token = "token";
client.login(token);
client.on("ready", () => {
client.channels.cache.get("channel_id").send("Hello!");
}); Before the ready event |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
rahultrivedi1800
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @rahultrivedi180, you have to wait for the client to be ready and send the message. You can use the following code:
Before the ready event
client.channels.cache.get("channel_id")
is undefined because the channel is not cached.