So what I am trying to do is, my discord bot listens for attachments then takes them and sends them to a particular channel, I want it to also react it with and now I saw some solutions but they require message id and channel id, my channel id would remain the same but my message id would change every time I send an attachment how do I make it so it reacts to the attachment into that channel
My code:-
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('👎'))
}
});
})
I have tried yes.react('')
but it does not work and replies with yes.react is not a function
Would be grateful if someone helps me with this.
Channel#send
returns a promise. Meaning we can use an asynchronous function
in order to define the channel sending method using await
(Send the message before defining it), and have our bot react to the newly sent message.
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('👎')
}
});
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.