无法弄清楚使用变量的语法我必须搜索用户是否有角色

CarrymesenpaiUwU

到目前为止,我的代码正确收集了我要搜索的服务器 ID、我要查找的角色 ID 以及邀请机器人的任何人的公会所有者 ID。

我需要它做的是检查它是否OwnerId具有我之前在服务器中提到的角色。

这是我到目前为止所得到的,但我觉得我错过了一些简单的东西。

/// adding a guild to the database upon invite
bot.on('guildCreate', async (guild) => {
    // Guild the user needs to have the role in
    let guildA = process.env.BOT_GUILD;
    console.log(guildA);

    // Role that the user needs
    let requiredRole = process.env.PAID_ROLE;
    console.log(requiredRole);

    // Member object of the user in guildA
    let guildOwner = await guild.members.fetch(guild.ownerID);
    
    let OwnerId = guildOwner.guild.ownerID;
    console.log(OwnerId);
    
    //Check if they have the role 
    if (guildA.OwnerId.cache.has(`${requiredRole}`))

我也尝试添加.rolesafterOwnerId和 before .cache,但出现错误。

如果有人有更多关于这类事情如何运作的信息,那就太好了,确切地知道要谷歌搜索什么。

佐尔特·梅萨罗斯

OwnerId不会有任何角色,因为它只是一个雪花/ID。如果您想检查公会所有者是否拥有 ID 为的角色process.env.PAID_ROLE(如果它是 ID 而不仅仅是角色名称...),您可以将所有者作为成员获取,并检查他们的roles' 是否缓存了has此 ID:

bot.on('guildCreate', async (guild) => {
  // guild the user needs to have the role in
  // do you use it anywhere?!
  let guildA = process.env.BOT_GUILD;

  // member object of the owner of the guild the bot just joined
  let guildOwner = await guild.members.fetch(guild.ownerID);

  // check if that guildOwner has the role required
  let ownerHasPaidRole = guildOwner.roles.cache.has(process.env.PAID_ROLE);

  if (ownerHasPaidRole)
    console.log(`Woohoo, ${guildOwner} has the required role`);
});

编辑:如果您想获取属于您公会的 ID 为 的成员process.env.BOT_GUILD,则需要使用YOUR_GUILD#members.fetch(guild.ownerID). 要通过其 ID 获取您的公会,您也可以获取它。bot.guilds返回机器人当前正在处理的所有公会,因此您可以使用它的fetch()方法

bot.on('guildCreate', async (guild) => {
  // guild the user needs to have the role in
  let myGuild = await bot.guilds.fetch(process.env.BOT_GUILD);

  // get the member object of the owner on myGuild
  let guildOwner = await myGuild.members.fetch(guild.ownerID)

  if (!guildOwner)
    return console.log(`Oops, ${guild.owner} is not a member of your server.`)

  // check if that guildOwner has the role required on myGuild
  let ownerHasPaidRole = guildOwner.roles.cache.has(process.env.PAID_ROLE);

  if (ownerHasPaidRole)
    console.log(`Woohoo, ${guildOwner} has the required role`);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我无法通过语句弄清楚语法问题

我无法弄清楚将分母的异常抛出为 0 的有理类的语法

无法弄清楚我的for循环中有什么语法错误

我无法弄清楚如何传递用户的输入

无法弄清楚我的条件有什么问题

无法弄清楚如何为我的函数使用参数

无法弄清楚用户片段

我无法弄清楚这个查询

我无法弄清楚这些错误

无法弄清楚如何使用 IF 语句

我必须弄清楚数组中的数字是否是给定数字的因数

无法弄清楚我的SQL语法出了什么问题

无法为我的强类型视图弄清楚剃刀语法

无法弄清楚我的 C++ 程序中模板嵌套类的语法

我无法弄清楚查看此数据框特定实例的语法

Scala-使用DFS检测周期吗?我的代码有错误,我似乎无法弄清楚为什么

我想弄清楚Cookie /会话变量如何交互以验证用户会话

无法弄清楚 scala compose 函数中的语法

无法弄清楚这个语法错误是什么

无法弄清楚Python中的if / else语法

我无法弄清楚如何将用户输入追加到在Javascript数组

无法弄清楚从哪里开始允许用户订阅我的Rails应用程序中的论坛

无法弄清楚为什么 javascript 不存储我的变量

无法遍历链表,无法弄清楚我的方法有什么问题?

我的公式有问题,我无法弄清楚哪个公式和位置

我的程序中有一个错误,我无法弄清楚

无法弄清楚为什么我的代码无法呈现

我无法弄清楚我的Python Socket错误

无法弄清楚崩溃