javascript - 删除任何消息上的特定反应表情 (Discord.js)
问题描述
我想做一个“被禁止的反应”。我得到了以下代码,但它只删除了对机器人发送的消息的反应。
client.on('messageReactionAdd', async (reaction, user) => {
console.log(reaction);
if(reaction.emoji.name === 'pinkphallicobject')
reaction.remove();
});
我怎样才能让它删除来自任何人的所有消息的特定反应?
解决方案
要messageReactionAdd
在旧消息上触发事件,您需要在ready
触发事件时将旧消息缓存在服务器中,您可以这样做:
client.once('ready', () => {
var guild = client.guilds.cache.first();// you can find the server you want it to work on in a different way or do this for all servers
guild.channels.cache.forEach(channel => {
if(channel.type == 'text'){//do this for text channels only
channel.messages.fetch({limit: 100}).then(() => {
console.log('cached 100 or less messages from the: ' + channel.name + 'text channel.');
});
}
});
}
推荐阅读
- linux - 故障处理程序(内核)返回线程进程是否终止
- assembly - 我似乎无法让这个 16 位内存检测汇编代码工作
- powershell - 处理 powershell 数组中的项目 - 多个项目
- python - 删除所有键后大 python 字典的内存占用
- swiftui - WKWebView 自定义链接可在 SwiftUI 中打开 WhatsApp 等应用
- java - Java 相当于 Scala 的未来?
- python - Python Selenium - 有什么方法可以在这个文本框中发送文本?
- python - 重命名包含子字符串的列 - Pandas
- python - Cmd 提示符执行不带 py 的代码,但忽略命令行参数(自动化无聊的东西)
- c++ - 无法在 OS X Big Sur 上编译 c++,“ld: library not found for -lgcc_s.10.4”