javascript - 如何使用 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
}
});
解决方案
自从我看到您的编辑后,我在评论中回答了您原始帖子的大部分内容。
如果尚未完成,您必须在Discord Developer Portal - ApplicationsMessage Content
上启用您的机器人意图(然后选择您的应用程序,单击“Bot”按钮,向下滚动到Priveleged Gateway Intents然后打开“消息内容”,并且可能,取决于您的计划,“服务器成员”)
如果您的机器人曾经达到 100 台服务器,假设它是公开的,那么您需要验证您的机器人以继续使用意图。
推荐阅读
- c++ - C ++将所有文件从一个目录移动到另一个目录
- java - 我无法让图像加载到小程序上
- groovy - 在 Katalon Studio 中执行 Junit 测试时出现内部错误
- c# - Response.Redirect() 在 Response.Flush() 之后;
- java - 使用套接字时,json文件未完成
- python - 如何从图像中裁剪边界框
- python - 使用 pandas 聚合表
- ios - Xcode 存档错误:命令操作工具失败,退出代码为 255
- mariadb - Mariadb 10.3 如何导出/导入序列
- java - 如何使用 Woodstox writeRaw WITH 缩进重用部分 XML 文档?