debugging Discord机器人未交互

sshcrbum  于 2023-02-13  发布在  其他
关注(0)|答案(1)|浏览(140)

最近我做了一个不和谐的机器人,禁止新成员自动当有人谁创建了他们的帐户不到30天前加入.问题是,当有人加入什么都没有发生,也没有日志显示任何东西.想知道什么可能是问题.谢谢!!

`const { Client, Intents,GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: GatewayIntentBits.Guilds
});

   client.on('guildMemberAdd', member => {
  console.log(`${member.user.username} csatlakozott a szerverhez.`);
  const currentTime = Date.now();
  const creationTime = member.user.createdAt.getTime();
  const ageInMs = currentTime - creationTime;
  const ageInDays = ageInMs / 1000 / 60 / 60 / 24;

  if (ageInDays < 30) {
    console.log(`${member.user.username} fiókja egy hónapnál fiatalabb. Bannolás és üzenet küldése...`);
    member.ban({ reason: 'Fiók létrehozási dátuma egy hónapnál fiatalabb' });
    member.send('Sajnáljuk, de a fiókod egy hónapnál fiatalabb, így nem tudsz csatlakozni a     szerverhez.')
      .then(() => console.log(`Üzenet elküldve ${member.user.username}-nek.`))
      .catch(error => console.error(`Hiba történt az üzenet küldése közben: ${error}`));
  }    
});

client.login('token')
  .then(() => console.log('Bot bejelentkezve.'))
  .catch(error => console.error(`Hiba történt a bejelentkezés közben:  ${error}`));
`

尝试:加入多个服务器,日志应该显示加入,并自动禁止成员。

kpbpu008

kpbpu0081#

根据此链接www.example.comhttps://discordjs.guide/popular-topics/intents.html#enabling-intents
如果您希望机器人为新成员发布欢迎消息(GUILD_MEMBER_ADD-discord.js中的"guildMemberAdd"),则需要GuildMembers特权Intent,等等。
更改此

const client = new Client({
  intents: GatewayIntentBits.Guilds
});

为此

const client = new Client({
    intents: [
        GatewayIntentBits.GuildMembers
    ]
})

这应该也行得通(虽然我没有尝试过)

const client = new Client({ ws: { intents: ['GUILD_MEMBER_ADD'] } });

重新启动你的机器人,它应该工作。我设法测试了它,并禁止了一个新帐户(我没有测试你的机器人是否也禁止旧帐户)
您可以在www.example.com找到Intent列表https://discord.com/developers/docs/topics/gateway#list-of-intents

相关问题