【问题标题】:Discord Bot Posting a Channel LinkDiscord Bot 发布频道链接
【发布时间】:2020-07-13 19:58:48
【问题描述】:

这是我到目前为止所拥有的,并且有效。我正在尝试在消息末尾添加一个#channel-name-link。

bot.on('guildMemberAdd', member => {
    const welcome = member.guild.channels.cache.find(channel => channel.name === "on-the-leash");
    if (!welcome) return;
    welcome.send("Welcome " + member.toString() + "more message here!!" + message.guild.channels.cache.get('channelID').toString());
});

现在我收到一条错误消息,说消息未定义。我是 node.js 的新手。我习惯使用 PowerShell 和 Bash。我用 Java 和 C++ 编程过,但距离我真正用它们做任何事情已经有一两年了。感谢所有帮助。

任何帮助将不胜感激

【问题讨论】:

    标签: bots discord discord.js


    【解决方案1】:

    您使用的是 discord.js v11 还是 v12? 您想使用它的 ID 来获取频道,还是更愿意使用它的名称来查找它?

    编辑:

    message.guild.channels 之后添加.cache,应该可以解决您的问题

    您的解决方案是:

    welcome.send("Welcome " + member.toString() + "more message here" + message.guild.channels.cache.find(channel => channel.name === "rules" ).toString());
    
    

    welcome.send("Welcome " + member.toString() + "more message here" + message.guild.channels.cache.get("channelID").toString());
    
    

    【讨论】:

    • 我使用的是 v12,无论哪种方式都可以。我知道这个频道的 ID,但如果需要,我可能想稍后切换到名称。
    • 我试过了,没用,我还注意到我的代码没有显示出来,所以现在你可以看到我在做什么了。
    • 不,你误解了我的意思,我再次编辑我的答案给你解决方案
    【解决方案2】:

    感谢@Syntle 的帮助,你让我到达了我需要的地方

    bot.on('guildMemberAdd', member => {
        const welcome = member.guild.channels.cache.find(channel => channel.name === "on-the-leash");
        const channel = member.guild.channels.cache.get('#ChannelID#').toString();
        if (!welcome) return;
        welcome.send("Welcome " + member.toString() + "More Message Here" + channel);
    });
    

    【讨论】:

      猜你喜欢
      • 2019-05-17
      • 2019-05-05
      • 2021-01-10
      • 2021-02-26
      • 1970-01-01
      • 2018-11-24
      • 2018-09-22
      • 2021-07-20
      • 2020-11-04
      相关资源
      最近更新 更多