簡體   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