【问题标题】:Bot won't messsage on join (djs)Bot 不会在加入时发送消息(djs)
【发布时间】:2021-03-24 16:40:21
【问题描述】:

我的机器人在加入时不发送消息。

client.on('guildMemberAdd', member => {
    const linkId = pool.createLink(client.id);
    const embed = new Discord.MessageEmbed()
        .setTitle('reCAPTCHA Verification')
        .setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
        .setColor('BLUE')
    member.send(embed)
})

【问题讨论】:

  • 它做了什么?有什么错误吗?
  • nothing no error or nothing else
  • 嗨@Tired。在提出问题时,您应该尽可能多地分享问题。你的环境是什么样的?含义,什么浏览器,您正在使用的相关库的版本,到目前为止您尝试过哪些有效的方法,以及它不起作用的具体情况。仅此一项还不足以让任何人参与进来。

标签: javascript discord.js


【解决方案1】:

鉴于您的代码中没有出现任何错误,我假设您根本不会触发 guildMemberAdd 事件。这可以通过在当前代码中的 guildMemberAdd 事件处理程序中添加 console.log 语句并让成员加入公会来快速确认。

我能想到会发生这种情况的唯一原因是 Discord API 相对较新的intents 功能。您需要订阅特定的意图才能可靠地接收关联事件。 guildMemberAdd 位于 the list of events 上,可能需要订阅意图。

这是您在定义client 的任何地方都需要实施的一种可能的修复方法:

const intents = ["GUILDS", "GUILD_MEMBERS"];
const client = new Discord.Client({intents: intents, ws:{intents: intents}});

如果您已经正确使用意图,那么我建议您使用上述console.log 以确保触发guildMemberAdd 事件。如果不是,那么这就是答案。请注意,您必须使用 discord.js v12.x.x 才能使用 Intent,因此如果您使用的是旧版本,则需要更新以解决您的问题。

可能还需要在其 discord 开发者页面上为您的机器人启用以下设置,因为我认为 guildMemberAdd 是特权意图的一部分:

相关资源:
List of intents and associated events
General info about intents

【讨论】:

  • 除此之外,您还必须确保您向其发送消息的用户没有阻止机器人,并且没有配置他们的设置以使他们不会收到DM。在发送消息之前您无法“检测”到这一点,但您可以在您的 member.send() 末尾添加一个 .catch() 以在机器人无法将消息发送给加入的成员时执行一些其他代码。
猜你喜欢
  • 2019-01-16
  • 2021-06-06
  • 2023-03-07
  • 2021-09-10
  • 2021-01-09
  • 1970-01-01
  • 2021-06-24
  • 1970-01-01
  • 2020-12-05
相关资源
最近更新 更多