[英]How to react to a message attachment discord.js
所以我想要做的是,我的 discord 机器人侦听附件然后将它们发送到特定频道,我希望它也能对其做出反应,现在我看到了一些解决方案,但它们需要消息 ID 和频道 ID,我的频道 ID 将保持不变,但每次我发送附件时我的消息 ID 都会更改我如何制作它以便它对进入该频道的附件做出反应
我的代码:-
client.on("message", async message => {
message.attachments.forEach((attachment) => {
if (attachment.width && attachment.height) {
if (message.author.bot) return
let yes = attachment
const channel = client.channels.cache.find(channel => channel.name === "llllllounge")
channel.send(yes)
.then(() => attachment.react('👍'))
.then(() => attachment.react('👎'))
}
});
})
我已经尝试过yes.react('')
但它不起作用并回复yes.react is not a function
如果有人帮助我,将不胜感激。
Channel#send
返回 promise。 这意味着我们可以使用asynchronous function
来定义使用await
的通道发送方法(在定义之前发送消息),并让我们的机器人对新发送的消息做出反应。
client.on("message", message => {
message.attachments.forEach(async (attachment) => {
if (attachment.width && attachment.height) {
if (message.author.bot) return
let yes = attachment
const channel = client.channels.cache.find(channel => channel.name === "llllllounge")
const msg = await channel.send(yes)
await msg.react('👍')
msg.react('👎')
}
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.