【发布时间】:2021-04-12 17:13:28
【问题描述】:
所以我编写了一个帮助命令,通过在频道中输入!help 来执行该命令并触发机器人。我用createReactionCollector() 做了一个反应分页,机器人用我反应的内容编辑消息。请注意,以下代码是MWE。当我在频道中执行它时,它就像一个魅力,并且用户的反应也将立即被删除。到目前为止一切顺利。
msg.channel.send('Page: 1️⃣').then(sentMsg => {
const pages = ['1️⃣','2️⃣','3️⃣']
pages.map(emj => sentMsg.react(emj))
const collector = sentMsg.createReactionCollector((args, user) => {
return pages.includes(args._emoji.name) && user.id === msg.author.id && !user.bot
}, { max: Infinity })
collector.on('collect', (reaction, user) => {
switch (reaction.emoji.name) {
case pages[0]: sentMsg.edit('Page: '+pages[0]); break;
case pages[1]: sentMsg.edit('Page: '+pages[1]); break;
case pages[2]: sentMsg.edit('Page: '+pages[2]); break;
}
reaction.users.remove(user).catch(e => {
if (e.code == 50013) {
msg.channel.send('[!] Cannot remove reaction of a user. Insufficient permissions.')
} else {
console.error(e)
}
})
})
})
问题
我希望它通过带有msg.author.send() 的 DM(直接消息)发送。它仍然会编辑消息,但不会立即删除反应,如上面的 GIF 所示。相反,我收到以下错误:
DiscordAPIError: Cannot execute action on a DM channel
at RequestHandler.execute (C:\xampp\htdocs\ht\discord\mihojs_beta\node_modules\discord.js\src\rest\R
equestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async RequestHandler.push (C:\xampp\htdocs\ht\discord\mihojs_beta\node_modules\discord.js\src\res
t\RequestHandler.js:39:14) {
method: 'delete',
path: '/channels/794019488176799744/messages/796506596003545098/reactions/2%EF%B8%8F%E2%83%A3/36298203
0025424907',
code: 50003,
httpStatus: 403
}
我知道Collector 对象收集有关对其做出反应的用户的数据,我假设在 DM 中它不起作用,因为它不是一个频道,因此不是公会/服务器的一部分 - 我说的对吗?我似乎在guide 中找不到它,有人知道解决方案或解决方法吗?
【问题讨论】:
标签: javascript node.js discord.js