Skip to content

Send message to channels - discord.js #5196

Closed Locked Answered by Androz2091
rahultrivedi1800 asked this question in Q&A
Discussion options

You must be logged in to vote

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 client.channels.cache.get("channel_id") is undefined because the channel is not cached.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Androz2091
Comment options

Answer selected by rahultrivedi1800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants