Bot 不会在加入时发送消息(djs)

Bot won#39;t messsage on join (djs)(Bot 不会在加入时发送消息(djs))
本文介绍了Bot 不会在加入时发送消息(djs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

client.on('guildMemberAdd', member => {常量 linkId = pool.createLink(client.id);const embed = new Discord.MessageEmbed().setTitle('reCAPTCHA 验证').setDescription(`要访问此服务器,您必须解决验证码.链接将在 15 分钟后过期.
http://${domain == '' ? 'localhost:8050' : domain}/verify/${链接ID}`).setColor('蓝色')成员.发送(嵌入)})

解决方案

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

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

相关资源:
意图和相关事件列表
有关意图的一般信息

My bot doesn't send the message on join.

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.
http://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
        .setColor('BLUE')
    member.send(embed)
})

解决方案

Given that you aren't getting any errors in your code, I'm assuming the guildMemberAdd event isn't triggering for you at all. This could be quickly confirmed by putting a console.log statement inside of your guildMemberAdd event handler in your current code, and having a member join the guild.

The only reason I can think of that this would occur, is the Discord API's relatively new intents feature. You need to subscribe to specific intents in order to reliably receive the affiliated events. guildMemberAdd is on the list of events that may require subscription to an intent.

Here's one possible fix you'll need to implement wherever you are defining client:

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

If you are already properly using intents, then I would recommend using console.log as aforementioned to ensure the guildMemberAdd event is triggering. If not, then this is the answer. Note that you must use discord.js v12.x.x to use intents, so if you're using an older version you'll need to update to fix your issue.

You may also need to enable the below setting for your bot on its discord developers page, as I think guildMemberAdd is part of a privileged intent:

Relevant resources:
List of intents and associated events
General info about intents

这篇关于Bot 不会在加入时发送消息(djs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)