如何获取已加入用户/成员的公会ID(Discord.js)

时间:2020-06-02 17:07:59

标签: javascript bots discord discord.js

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

settingss.findOne({
  guildID: guild.ID // <---- Trying to figure out what i want over here
}, async (err, settings) => {

    var role = member.guild.roles.cache.get(role => role.name === settingss.joinrolename);

    if (!role) return;

    member.roles.add(role);

    const channel = member.guild.channels.cache.get(channel => channel.name === settingss.welcomechannelname);

    if (!channel) return;

    channel.send(`Welcome to the server, ${member}`);

  });

});

我似乎无法弄清楚如何获得公会ID。

我尝试了guild.memberCount这也不起作用。

2 个答案:

答案 0 :(得分:0)

我认为member.guild.id应该可以解决问题:)

答案 1 :(得分:0)

您可以使用member参数使用member.guild.id来获取行会ID:

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

  settingss.findOne({
    guildID: member.guild.id
  }, async (err, settings) => {

    var role = member.guild.roles.cache.get(role => role.name === settingss.joinrolename);

    if (!role) return;

    member.roles.add(role);

    const channel = member.guild.channels.cache.get(channel => channel.name === settingss.welcomechannelname);

    if (!channel) return;

    channel.send(`Welcome to the server, ${member}`);

  });

});