到目前为止,我的代码正确收集了我要搜索的服务器 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}`))
我也尝试添加.roles
afterOwnerId
和 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] 删除。
我来说两句