Discord 机器人不回复消息
Discord bot not answering messages
我一直在尝试一个新项目,该项目是在节点中用 discord.js 编写一个不和谐的机器人。 discord.js 文档中的交互源代码有效,但是,当我按照在线教程进行操作时,机器人不会回复我在 discord 服务器中的消息。请纠正我!,机器人似乎在我的控制台正常工作时上线。但剩下的就是历史了
const Discord = require('discord.js');
const env = require("./botconfig.json"); //json file containing tokens & IDs
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
let prefix = env.prefix;
client.on("ready", ()=>{
console.log(`${client.user.tag} is online in ${client.guilds.cache.size} servers`)
console.log(`the prefix is ${prefix}`);
})
client.on("messageCreate", Message => {
if (Message === "ping") {
Message.channel.send('Pong.');
}
});
client.login(env.token);
在 client.on("messageCreate"
上,第二个参数是一个接受 Message
对象的函数,不是 作为字符串的消息! (检查 class 此处 https://discord.js.org/#/docs/discord.js/stable/class/Message)。您可能想尝试以下方法:
// Access the `content` property of the message
if (Message.content === "ping") {
Message.channel.send('Pong.');
}
您看到的教程似乎也有点过时了。 Discord.js 有很多新东西可以让这些变得更容易、更有条理。我建议您在遵循非常好的官方文档的同时尝试构建您的机器人 :) https://discord.js.org/#/docs/discord.js/stable/general/welcome
messageCreate
事件不传递字符串,它传递一个Discord.jsMessageclass实例,因为DJS是object-oriented。只需访问 .content
属性 例如 message.content
.
我一直在尝试一个新项目,该项目是在节点中用 discord.js 编写一个不和谐的机器人。 discord.js 文档中的交互源代码有效,但是,当我按照在线教程进行操作时,机器人不会回复我在 discord 服务器中的消息。请纠正我!,机器人似乎在我的控制台正常工作时上线。但剩下的就是历史了
const Discord = require('discord.js');
const env = require("./botconfig.json"); //json file containing tokens & IDs
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
let prefix = env.prefix;
client.on("ready", ()=>{
console.log(`${client.user.tag} is online in ${client.guilds.cache.size} servers`)
console.log(`the prefix is ${prefix}`);
})
client.on("messageCreate", Message => {
if (Message === "ping") {
Message.channel.send('Pong.');
}
});
client.login(env.token);
在 client.on("messageCreate"
上,第二个参数是一个接受 Message
对象的函数,不是 作为字符串的消息! (检查 class 此处 https://discord.js.org/#/docs/discord.js/stable/class/Message)。您可能想尝试以下方法:
// Access the `content` property of the message
if (Message.content === "ping") {
Message.channel.send('Pong.');
}
您看到的教程似乎也有点过时了。 Discord.js 有很多新东西可以让这些变得更容易、更有条理。我建议您在遵循非常好的官方文档的同时尝试构建您的机器人 :) https://discord.js.org/#/docs/discord.js/stable/general/welcome
messageCreate
事件不传递字符串,它传递一个Discord.jsMessageclass实例,因为DJS是object-oriented。只需访问 .content
属性 例如 message.content
.