欢迎消息问题 | 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.**"));

})

我将如何解决这个问题?


FFIVE
浏览 132回答 3
3回答

隔江千里

有一种更简单的方法来做你想做的事情。复制该频道的 ID,然后像这样在您的代码中获取该频道:bot.on('guildMemberAdd',&nbsp;(member)&nbsp;=>&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;channel&nbsp;=&nbsp;member.guild.channels.cache.get('channel-id'); &nbsp;&nbsp;&nbsp;&nbsp;channel.send('Welcome'); });

一只萌萌小番薯

我的猜测是,如果找不到该频道,则会发生该错误。未找到的频道将返回未定义。检查频道是否存在,如果不存在,它将不会运行其余的功能。

慕码人2483693

也许试试这个?:client.on('guildMemberAdd', member => {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; let welChannel = member.guild.channels.cache.find(ch => ch.name === "・𝘪𝘮𝘴𝘨")&nbsp; &nbsp; const exampleEmbed = new Discord.MessageEmbed()&nbsp; &nbsp; &nbsp; &nbsp; .setColor('RANDOM')&nbsp; &nbsp; &nbsp; &nbsp; .setTitle(`Welcome to lovell <$, **${member.user.username}**`)&nbsp; &nbsp; &nbsp; &nbsp; .setImage('https://images-ext-1.discordapp.net/external/Gy-micqoX7qrlivnytbmFgfTbxPx_CSvgChFLE3qC7g/https/media.discordapp.net/attachments/755425128635957348/758525058934767617/HaxzUWa46sK5CXKzIR.gif')&nbsp; &nbsp; &nbsp; &nbsp; .setFooter('Boost Us');&nbsp; &nbsp; 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.**"));})如果这不起作用,则可能是机器人找不到频道・𝘪𝘮𝘴𝘨。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript