我的Discord Bot遇到问题。 id的作用是,它在Command上创建一个Channel,并为特定角色分配权限“ VIEW_CHANNEL”。现在的问题是,我需要获取角色的ID。我已经尝试过了(下面的代码),但是它不起作用。
let admin = message.guild.roles.cache.find(role => role.name === "LuisChatAdmin").id;
编辑:这是错误。对不起,我忘了附上它。
(node:11956) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role. at Function.resolve (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\structures\PermissionOverwrites.js:177:28) at C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\managers\GuildChannelManager.js:109:81 at Array.map (<anonymous>) at GuildChannelManager.create (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\managers\GuildChannelManager.js:109:51) at Client.<anonymous> (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\bot.js:230:34) at Client.emit (events.js:333:22) at MessageCreateAction.handle (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) at Object.module.exports [as MESSAGE_CREATE] (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) at WebSocketShard.onPacket (C:\Users\User\Desktop\Stuff\Scheiße die sich verpissen soll\LuisChat\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
编辑2:这是整个代码:
client.on('message', message => { if (message.content === "!setup") { if (message.channel.type === "text") { let admin = message.guild.roles.cache.find(role => role.name === "LuisChatAdmin").id; let bot = "752206832843620525"; if (message.guild.member(message.author).hasPermission("ADMINISTRATOR")) { message.delete(); if (message.guild.roles.cache.find(role => role.name === "LuisChatBypass")) { message.channel.send({ embed: { color: 15158332, author: { }, title: "Fehler", description: "Die Rollen existieren bereits.", }}) } else { message.guild.roles.create({ data: { name: "LuisChat Bypass", color: 'GREEN', } }) message.guild.roles.create({ data: { name: 'LuisChat Admin', color: 'RED', } }); message.guild.channels.create('luischat', { type: 'category', permissionOverwrites: [ { id: bot, allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'], }, { id: admin, allow: ['VIEW_CHANNEL'], }, { id: message.guild.id, deny: ['VIEW_CHANNEL'], } ] }) } } } } })
答案 0 :(得分:0)
尝试一下
if(message.member.roles.cache.some(r=>["USER ROL"].includes(r.name)) ) {
message.channel.send('MESSAGE')
} else {
message.channel.send('u can't use because you don´t have permissions')
}