首页 > 解决方案 > Discord.js 公会成员添加

问题描述

我正在制作一个机器人来检测用户何时加入。当我的测试帐户加入时,下面的代码不起作用。它仅在用户第一次加入时才有效。如果是这样,我怎样才能让它每次都工作。

client.on('guildMemberAdd', member => {
        // Send the message to a designated channel on a server:
        const channel = member.guild.channels.cache.find(ch => ch.name === 'general-chat');
        // Do nothing if the channel wasn't found on this server
        if (!channel) return;
        // Send the message, mentioning the member
        channel.send(`Welcome to the server, ${member}`);
      });

标签: discord.js

解决方案


您可能必须在Discord Developer Portal上的机器人设置中启用 Presence Intent ,这样才能检测到新成员。这是一个截图


推荐阅读