简体   繁体   English

如何检测用户加入 discord.js 的公会?

[英]How do I detect what guild a user joins in discord.js?

I use this code here to detect when a user joins and send a message, but I want it to only send a message when it joins the guild "Bongo's Diner":我在这里使用此代码来检测用户何时加入并发送消息,但我希望它仅在加入公会“Bongo's Diner”时发送消息:

client.on('guildMemberAdd', member =>{

    const welcomeChannel = client.channels.cache.get('713215120305815612');
    welcomeChannel.send(`Welcome to the server, <@${member.id}>. I hope you enjoy your stay here at Bongo's Diner.

Be sure to check out <#713227378306056244> to grab a color and learn how to get ping roles. If you have a question, check out <#713194923909972159>.`);

});

Since you are already using guildMemberAdd and have access to a member instance, just call member.guild :由于您已经在使用guildMemberAdd并且可以访问member实例,因此只需调用member.guild

const guild = member.guild;
console.log(guild);

https://discord.js.org/#/docs/main/stable/class/GuildMember https://discord.js.org/#/docs/main/stable/class/GuildMember

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM