亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

歡迎消息問題 | Discord.js

歡迎消息問題 | Discord.js

FFIVE 2023-05-11 15:58:08
我有一個歡迎消息機器人,它會在每次有人加入時發送歡迎消息,但有時,它會在控制臺中拋出一條錯誤消息:    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.**"));})我將如何解決這個問題?
查看完整描述

3 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

有一種更簡單的方法來做你想做的事情。復制該頻道的 ID,然后像這樣在您的代碼中獲取該頻道:

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


查看完整回答
反對 回復 2023-05-11
?
一只萌萌小番薯

TA貢獻1795條經驗 獲得超7個贊

我的猜測是,如果找不到該頻道,則會發生該錯誤。未找到的頻道將返回未定義。檢查頻道是否存在,如果不存在,它將不會運行其余的功能。



查看完整回答
反對 回復 2023-05-11
?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

也許試試這個?:


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.**"));

})

如果這不起作用,則可能是機器人找不到頻道?????????。


查看完整回答
反對 回復 2023-05-11
  • 3 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號