【问题标题】:Discord.js V13 Welcome MessageDiscord.js V13 欢迎消息
【发布时间】:2021-12-24 06:59:35
【问题描述】:

我对创建机器人还很陌生,所以这条欢迎消息在 discord.js v12 中可以恢复,但在 v13 中不再适用于我。当有人加入服务器时,我试图在特定频道中发送消息,但我检查了,.send 在 GuildChannel 上不存在。我查看了文档,但他们都在谈论发送消息嵌入,但我只是想向 TextChannel 发送一条普通消息。这是代码。

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on('guildMemberAdd', guildMember => {
    guildMember.guild.channels.cache.get('474431129613762571').send(`**Welcome to the discord server, <@${guildMember.user.id}>!**`);
});

如果需要,我可以提供更多信息。任何帮助将不胜感激。

【问题讨论】:

  • 你需要GUILD_MEMBERS 在代码和不和谐开发者门户中的意图。 .send 存在于TextChannels 上,GuildChannel 只是它的扩展,.send 不存在,因为它可能是VoiceChannel! (实际上TextChannel 扩展了BaseGuildTextChannel 扩展了GuildChannel)
  • @MrMythical 您想留下您的建议作为评论吗?因为它对我有用,我想感谢你,但这不是答案。

标签: javascript node.js discord discord.js


【解决方案1】:

你需要GUILD_MEMBERSintent 在代码和不和谐开发者门户中。

const client = new Client({ 
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MEMBERS //also enable in discord developer portal
    ] 
})

要回答您其他问题的另一部分,.send 存在于TextChannels。 TextChannel 扩展 BaseGuildTextChannel 扩展 GuildChannel。之所以这样,是因为可以是VoiceChannel!

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 2021-01-25
    • 2021-04-11
    • 1970-01-01
    • 2021-09-23
    • 2021-10-09
    • 2018-04-03
    • 2021-10-07
    • 2020-09-10
    相关资源
    最近更新 更多