繁体   English   中英

欢迎信息的问题 | Discord.js

[英]Issues With Welcome Message | Discord.js

我有一个欢迎消息机器人,每次有人加入时都会发送一条欢迎消息,但有时,它会在控制台中抛出一个错误,说:

    member.guild.channels.cache.find(ch => ch.name === "・𝘪𝘮𝘴𝘨").send(exampleEmbed).catch(e => co    nsole.error(`Welcome Error in ${message.guild.name}`) | message.channel.send("__**ERROR:**__ ** Someone joined the server but I was 
le to catch it.**"));
                                                                   ^

TypeError: Cannot read property 'send' of undefined

代码:

client.on('guildMemberAdd', member => {


    const exampleEmbed = new Discord.MessageEmbed()
        .setColor('RANDOM')
        .setTitle(`Welcome to lovell <$, **${member.user.username}**`)
        .setImage('https://images-ext-1.discordapp.net/external/Gy-micqoX7qrlivnytbmFgfTbxPx_CSvgChFLE3qC7g/https/media.discordapp.net/attachments/755425128635957348/758525058934767617/HaxzUWa46sK5CXKzIR.gif')
        .setFooter('Boost Us');

    member.guild.channels.cache.find(ch => ch.name === "・𝘪𝘮𝘴𝘨").send(exampleEmbed).catch(e => console.error(`Welcome Error in ${message.guild.name}`) | message.channel.send("__**ERROR:**__ ** Someone joined the server but I was unable to catch it.**"));
})

我将如何解决这个问题?

有一种更简单的方法来做你想做的事情。 复制该频道的 ID,然后在您的代码中获取该频道,如下所示:

bot.on('guildMemberAdd', (member) => {
    const channel = member.guild.channels.cache.get('channel-id');
    channel.send('Welcome');
});

我的猜测是,如果找不到频道,就会发生该错误。 未找到的频道将返回 undefined。 DiscordJS 网站上的这段代码将检查频道是否存在,如果不存在,它将不会运行其余的功能。

也许试试这个?:

client.on('guildMemberAdd', member => {
    
    let welChannel = member.guild.channels.cache.find(ch => ch.name === "・𝘪𝘮𝘴𝘨")

    const exampleEmbed = new Discord.MessageEmbed()
        .setColor('RANDOM')
        .setTitle(`Welcome to lovell <$, **${member.user.username}**`)
        .setImage('https://images-ext-1.discordapp.net/external/Gy-micqoX7qrlivnytbmFgfTbxPx_CSvgChFLE3qC7g/https/media.discordapp.net/attachments/755425128635957348/758525058934767617/HaxzUWa46sK5CXKzIR.gif')
        .setFooter('Boost Us');

    welChannel.send(exampleEmbed).catch(e => console.error(`Welcome Error in ${message.guild.name}`) | message.channel.send("__**ERROR:**__ ** Someone joined the server but I was unable to catch it.**"));
})

如果这不起作用,可能是机器人找不到・𝘪𝘮𝘴𝘨频道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM