【发布时间】:2021-04-11 07:38:48
【问题描述】:
我需要我的机器人自动添加这些表情符号,但是在列出“guildMemberAdd”事件时,我无法收到此消息。即。
client.on('guildMemberAdd', member => {
//Looked at docs, have no way to get this message
})
当有人加入时,我将如何查找这些消息?
【问题讨论】:
标签: discord.js
我需要我的机器人自动添加这些表情符号,但是在列出“guildMemberAdd”事件时,我无法收到此消息。即。
client.on('guildMemberAdd', member => {
//Looked at docs, have no way to get this message
})
当有人加入时,我将如何查找这些消息?
【问题讨论】:
标签: discord.js
经过一番努力,我为您的问题找到了一点解决方案:
在您已经看到之后,只要 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.
从这里,机器人将从我们选择的频道获取最新消息,并添加我们选择的反应。
【讨论】: