我的机器人没有阅读 Discord 聊天内容。我希望它阅读聊天记录,如果它找到某些单词,它会给出一定的响应。这是我当前的消息事件代码。这是我的第一个 JavaScript 项目,我刚刚开始学习它,所以请把它拆开,以便我可以学得更快:)
目前我可以让机器人加载到不和谐中。我可以使用 .node 打开它,但无法让它使用 message.content 读取消息。
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILD_MESSAGES", "DIRECT_MESSAGES"] });
var name = "Poker Bot";
var usersHand
let firstCardValue
let secondCardValue
let firstCardSuit
let secondCardSuit
//starts the bot and sets activity to a funny quote. it also will give a command prompt notification that the
// bot is online
client.on("ready", () => {
console.log(`Bot is online: ${name} !`);
client.user.setActivity('Burning The Fucking Casino Down');
});
//check discord chat to see if a user has posted.
client.on("messageCreate", message => {
//console.log is there to test user input. If it works the message in the discord channel will appear in console
console.log(`The user has said: ${message} `);
//look for poker hand ~~~ position ~~~~ event (ex: AA CO PF ) (PF= PreFlop)
if (message.content.toLowerCase == 'AK' || message.content.toLowerCase == 'AA' || message.content.toLowerCase == 'KK'){
message.reply("RECOMMENDED PLAY SHOVE: ALL IN")
}
最佳答案
.content
不是方法,而是属性,您现在还必须在机器人页面和代码中启用 Message Content
意图。
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILD_MESSAGES", "DIRECT_MESSAGES"] });
client.on("messageCreate", message => {
// || "String" like you did before would return "true" in every single instance,
// this is case sensitive, if you wanna make it case insensitive
// use `message.content.toLowerCase() == "lowercasestring"`
if (message.content == "AK" || message.content = "AA" || message.content == "KK") {
message.channel.send("Recommend Play is to shove all in" + message.author);
}
})
client.login(token);
关于javascript - Discord 机器人不读取 message.content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69893120/