【问题标题】:Discord.js TypeError: Cannot read property 'get' of undefinedDiscord.js TypeError:无法读取未定义的属性“get”
【发布时间】:2023-10-28 02:44:01
【问题描述】:

收到一条消息“TypeError: Cannot read property 'get' of undefined”我输入的任何频道 id 都很烦人,这是我的代码(非常简单的 atm)

   bot.on('guildMemberAdd',user => {
        user.guild.channels.get("[existing channel ID]").send("SomeText")
    });

我做错了吗?我尝试使用.find("name","channel_name") 得到了同样的错误,并尝试使用控制台日志作为“缓存”并得到 awnser“未定义”,因为它是我的机器人的一个关键功能,能够在特定频道中发布它很烦人...... ^^' 提前 TY 为您的帮助会继续努力使它工作^... ^^'

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    你需要使用.cache 来访问公会频道,所以在你的情况下它是user.guild.channels.cache.get("[existing channel ID]").send("SomeText")

    【讨论】:

      【解决方案2】:

      你可以测试一下:

      bot.on('guildMemberAdd',user => {
           const channelWelcome = user.guild.channels.cache.get("[channel's ID]"
           channelWelcome.send("Your text")
      });
      

      【讨论】: