【问题标题】:Welcome message not sending through Discord.js欢迎消息未通过 Discord.js 发送
【发布时间】:2021-10-07 12:23:35
【问题描述】:

所以我正在使用 discord.js 编写一个不和谐的机器人,其中一个功能是当新用户加入服务器时,机器人会发送一条消息。我暂时不做嵌入,以后可以自己做。

这是我专门为此功能制作的主要welcome.js 文件:

module.exports = (client) => {
    const channelId = '868192573011931185' //welcome channel
    client.on('guildMemberAdd', (member) => {
        console.log(member.name)

        const message = `Hello <@${member.id}> and welcome to ${guild.name}! 
        Please verify through the Server Captcha Bot in your DMs, 
        then read the rules in <#868192573263605884> 
        and lastly pick your roles in <#868192573263605880>!`

        const channel = member.guild.channels.cache.get(channelId)
        channel.send(message)
    })
}

在我的index.js 文件中,我刚刚导入了该文件,并添加了welcome(client)

但由于某种原因,我的代码没有出现在欢迎频道中...任何帮助将不胜感激。

【问题讨论】:

  • 事件不应该在函数中

标签: javascript discord.js bots


【解决方案1】:

检查您的意图是否打开并查看此post 以获取更多信息:

【讨论】:

  • 这行得通,谢谢,我还必须更改 ${guild.name} 但那行得通,谢谢!
【解决方案2】:

我不知道您的 index.js 的上下文,但我建议您阅读这个方便的指南,其中解释了如何处理单独文件中的事件。

基本上,它们会遍历 events 文件夹(您的 welcome.js 所在的文件夹)。 然后他们动态注册client 对象接收到的事件以通过这些事件文件执行。

链接:Event handling.

【讨论】:

    【解决方案3】:

    在你的代码中,而不是说

    const channel = member.guild.channels.cache.get(channelId)
    
    

    试着说:

    const channel = Client.channels.cache.get(channelId)
    

    希望它有效:)

    【讨论】:

    • 我认为它会,但它仍然没有发送任何消息:(
    • @PrezOfTheUnitedIdiots 有可能您没有启用您的服务器成员的意图,请转到开发门户并打开它,看看它是否有效 :)
    猜你喜欢
    • 2021-12-24
    • 2021-10-12
    • 2021-01-25
    • 2021-04-11
    • 2020-09-10
    • 2021-08-17
    • 2021-05-05
    • 2021-09-23
    • 2021-01-22
    相关资源
    最近更新 更多