【发布时间】:2020-12-31 09:23:55
【问题描述】:
所以我想知道一个不和谐的机器人是否可以计算图像有多少反应,并根据用户得到的反应给他们一个 xp 或 -xp 从那里级别有点像 reddits upvote 和 downvote 系统
【问题讨论】:
标签: javascript discord discord.js
所以我想知道一个不和谐的机器人是否可以计算图像有多少反应,并根据用户得到的反应给他们一个 xp 或 -xp 从那里级别有点像 reddits upvote 和 downvote 系统
【问题讨论】:
标签: javascript discord discord.js
我建议你在发布一个很长的可回答问题之前先上网看看。例如在反应页面上的 discord.js 指南 -> Link
是的,discord bot 在发送消息后可以创建一个消息收集器,在其中收集有关消息反应的所有信息(计数、用户、反应名称和 ID)
【讨论】:
您可以使用messageReactionAdd 事件和Map。
// create the map (use any name)
const karma = new Map();
// set up the event
client.on('messageReactionAdd', (reaction, user) => {
// check if the message has an attachment. you can add any other conditions here as well,
// such as the channel the message was sent in, etc.
// (to fetch the message object, use `reaction.message`
if (!reaction.message.attachments) return;
// you should also create a filter so that this will only trigger for certain reactions (upvotes and downvotes)
const upvote = '?' // for example
const downvote = '?' // for example
if (![upvote, downvote].includes(reaction.emoji.name)) return;
// check if the map has an entry for this user. if not, make one
if (!karma.has(user.id))
karma.set(user.id, reaction.emoji.name === upvote ? 1 : -1) // either give the new user 1 or -1 karma depending on the emote
// otherwise, increment/decrement karma total depending on emoji
else reaction.emoji.name === upvote ? karma.get(user.id)++ : karma.get(user.id)--
});
那么,只要你想得到某人的“业力”,你就可以使用:
karma.get('<ID Here>')
【讨论】:
messageReactionAdd 事件之外使用user 变量,只需输入用户ID(例如,您可以使用message.author.id 等)。另外,请提供返回[object Object]的代码行