响应欢迎消息 discord.js

时间:2021-01-05 14:31:38

标签: discord.js

每当用户加入我的服务器时,都会弹出这样的消息:Image of welcome message

我需要我的机器人自动添加这些表情符号,但是当列出“guildMemberAdd”事件时,我无法获得此消息。即。

client.on('guildMemberAdd', member => {
//Looked at docs, have no way to get this message
})

当有人加入时,我将如何查找这些消息?

1 个答案:

答案 0 :(得分:1)

经过一番努力,我找到了解决您问题的小方法:

在您已经看到之后,只要 Discord 公会所有者启用,Discord 会在 guildMemberAdd 事件上发送一条随机生成的小消息。当然,这条消息有一个消息对象,我们可以简单地使用方法 .lastMessage 获取它,该方法返回我们选择的频道中最新消息的对象。

使用这个,我们可以很容易地找到一种方法来继续对 Discord 生成的消息做出反应:

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.

从这里,机器人将从我们选择的频道获取最新消息,并添加我们选择的反应。