Whenever a user joins my server, a message like this pops up:
I need my bot to add those emojis automatically, however when listing to the "guildMemberAdd" event, I have no way to get to this message. ie.
client.on('guildMemberAdd', member => {
//Looked at docs, have no way to get this message
})
How would I go about finding these messages when someone joins?
After working a little bit, I've found a little solution to your question:
After you have already seen, Discord sends a little random generated message on a guildMemberAdd
event as far as it's enabled by the discord guild owner. This message, of course, has a message object, that we can simply get using the method .lastMessage
, which returns the latest message's object in the channel we choose.
Using this, we can easily figure out a way to go on about reacting to a Discord-generated message using:
setTimeout(() => {
const message = member.guild.channels.cache.get('welcome channel id').lastMessage
message.react('👍')
}, 500)
// Note: I have set a timeout of half a millisecond as it usually takes the bot longer to register
// a message at the same time of another command.
From here, the bot will get the latest message from the channel we've picked, and add the reactions we pick.