[英]Discord.js bot not sending messages
I'm trying out discord.js and trying to send message to a specific channel using a bot.我正在试用 discord.js 并尝试使用机器人将消息发送到特定频道。 But when I run the bot, it doesn't do anything, just keeps on running continuously.
但是当我运行这个机器人时,它什么也没做,只是一直持续运行。 The below snippet is what I tried-
下面的片段是我试过的-
import { Client, TextChannel } from "discord.js";
const token = "MY_BOT_TOKEN_ID";
console.log("Bot is starting...");
const client = new Client({
intents: []
});
let ChannelID = "MY_CHANNEL_ID";
client.login(token);
client.on("ready", () => {
console.log("Bot is ready!");
});
client.on("messageCreate", () => {
const channel12 = client.channels.cache.get(ChannelID) as TextChannel;
channel12.send("Hello World");
console.log("Message sent");
});
I figured out the issue, which is with the intents.我想出了这个问题,这是有意图的。 I replaced the current intents within
Client
with intents: [GatewayIntentBits.Guilds]
and it worked.我用
intents: [GatewayIntentBits.Guilds]
替换了Client
中的当前 intents 并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.