问题
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.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('BLUE')
member.send(embed)
})
回答1:
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
来源:https://stackoverflow.com/questions/65282277/bot-wont-messsage-on-join-djs