首页 > 解决方案 > 如何使用 message.content 将不和谐的聊天消息保存到变量中

问题描述

我正在构建一个不和谐的机器人,我需要将用户消息保存在一个变量中,但我目前无法让 message.content 出现在 console.log 中,并且我无法让我的机器人响应它是否读取不和谐频道中的某些字符串。


var name = "Poker Bot";
var allIn = "PUSH ALL IN";
var fold = "FOLD";
var tripleBBRaise = "3 BB RERAISE"

let usersHand;


//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 Darn Casino Down');
});

    //check discord chat to see if a user has posted.
client.on("messageCreate", message => {

    /*test to see if the chat input works.if working the users message will be saved as a string and then written in the console*/
    console.log(`The user has said: ${message} `);

//Users input will be a poker hand. If it is one of the 3 below then tell the user the given string 
if (message.content.toLowerCase == '/AK' || message.content.toLowerCase == '/AA' || message.content.toLowerCase == '/KK'){
    message.channel.send(`RECOMMENDED PLAY: ${allIn}`) + message.author
}
   
});

标签: javascriptnode.jsdiscorddiscord.jsbots

解决方案


自从我看到您的编辑后,我在评论中回答了您原始帖子的大部分内容。

如果尚未完成,您必须在Discord Developer Portal - ApplicationsMessage Content上启用您的机器人意图(然后选择您的应用程序,单击“Bot”按钮,向下滚动到Priveleged Gateway Intents然后打开“消息内容”,并且可能,取决于您的计划,“服务器成员”)

如果您的机器人曾经达到 100 台服务器,假设它是公开的,那么您需要验证您的机器人以继续使用意图。


推荐阅读