在 JavaScript Discord Bot 中,为啥 message.react() 是“不是函数”
Posted
技术标签:
【中文标题】在 JavaScript Discord Bot 中,为啥 message.react() 是“不是函数”【英文标题】:In a JavaScript Discord Bot, how come message.react() is "not a function"在 JavaScript Discord Bot 中,为什么 message.react() 是“不是函数” 【发布时间】:2020-11-01 18:20:40 【问题描述】:我正在我的服务器上运行一个不和谐的机器人。我想让机器人message.react()
处理我刚刚收到的消息。当我运行它时,它工作正常,直到我发送一条消息。
我收到此错误:
/Users/*****/Projects/Discord/DiscordBot/bot.js:22
.react("????")
^
TypeError: message.react is not a function
at DiscordClient.bot.on (/Users/revel/Projects/Discord/DiscordBot/bot.js:22:6)
at DiscordClient.emit (events.js:189:13)
at DiscordClient.handleWSMessage (/Users/revel/Projects/Discord/DiscordBot/node_modules/discord.io/lib/index.js:1854:11)
at WebSocket.emit (events.js:189:13)
at Receiver.ontext (/Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/WebSocket.js:841:10)
at /Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/Receiver.js:536:18
at Receiver.applyExtensions (/Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/Receiver.js:371:5)
at /Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/Receiver.js:508:14
at Receiver.flush (/Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/Receiver.js:347:3)
at Receiver.finish (/Users/revel/Projects/Discord/DiscordBot/node_modules/ws/lib/Receiver.js:541:12)
这是我的代码:
var Discord = require("discord.io");
var logger = require("winston");
var auth = require("./auth.json");
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console(),
colorize: true,
);
logger.level = "debug";
// Initialize Discord Bot
var bot = new Discord.Client(
token: auth.token,
autorun: true,
);
bot.on("ready", function (evt)
logger.info("Connected");
logger.info("Logged in as: ");
logger.info(bot.username + " - (" + bot.id + ")");
);
bot.on("message", (message) =>
message.react("????");
);
我正在运行discord.js
版本12.2.0
你能帮忙吗?
【问题讨论】:
这不是 Discord.js,这是 Discord.io 【参考方案1】:刚刚快速浏览了discord.io's docs,
您应该将message
事件的参数替换为正确的参数,如链接中所述:
client.on('message', function(user, userID, channelID, message, event) );
【讨论】:
【参考方案2】:您使用的是 discord.io,而不是 discord.js。
如果你想添加一个反应,你需要用这个替换你的消息事件监听器:
bot.on("message", (user, userID, channelID, message, event) =>
bot.addReaction(
channelID,
messageID: event.d.id,
reaction: "?"
);
);
参考资料:
client.on('message', function(user, userID, channelID, message, event) );
client.addReaction( )
event.d.id
【讨论】:
以上是关于在 JavaScript Discord Bot 中,为啥 message.react() 是“不是函数”的主要内容,如果未能解决你的问题,请参考以下文章
Discord bot 使用 javascript .sendMessage 不是函数
在 JavaScript Discord Bot 中,为啥 message.react() 是“不是函数”
制作 Discord Bot 时在 Javascript 中出现“意外的输入结束”
Discord Bot Javascript 命令,如果有问题