【发布时间】:2021-10-18 01:55:46
【问题描述】:
我正在尝试制作一个机器人,一旦用户发送特定消息,它就会向频道发送消息。我已经设法让它在机器人登录后发送一条消息,但 client.on() 函数不会做任何事情。如果我做错了什么,请告诉我,提前谢谢!
const { Client, Intents } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.login("<bot token>");
client.once("ready", () => {
console.log("Ready!");
channel.send("hello world"); //This works
const guild = client.guilds.cache.get("<server id>");
const channel = guild.channels.cache.get("<channel id>");
//This is the issue. Nothing happens when I send "!ping" in the server
client.on("message", message => {
if (message.content === "!ping") {
channel.send("pong");
}
});
});
【问题讨论】:
-
这能回答你的问题吗? message event listener not working properly
标签: javascript discord discord.js bots