javascript - Discord 机器人不读取 message.content

标签 javascript discord discord.js bots chat

我的机器人没有阅读 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/

相关文章:

javascript - 如何检查对象的属性是 getter 还是 setter?

javascript - 如何在一个单一的模式中用星星和数字做一个组合金字塔

javascript - D3 力导向图节点上的标签/文本

javascript - 等待 angular 4 服务中的 http 请求完成

python - Discord.py重写多服务器数据

javascript - Discord.js 机器人正在删除所有消息

javascript - message.content.includes 不适用于此代码

html - 带有描述和图像的 URL 元标记(在 Skype、Discord 中)

javascript - 'DiscordAPI错误: Unknown Message' when deleting message upon a reaction

javascript - Discord.js (v13) SlashCommandBuilder addIntegerOption 设置范围