似乎无法创建此角色 discord js
2021-06-23
60
我查看了文档,这就是我所展示的内容,所以我只是对其进行了一些编辑,使其成为我希望角色具有的权限,然后从那里我尝试了该命令并收到错误。我尝试了几种方法仍然无法使其工作这是我第一次尝试这个所以我可以看到为什么它不起作用
const Discord = require("discord.js")
module.exports = {
name: 'muterolecreate',
usage: '%muterolecreate',
discription: "makes a muterole",
execute(client, message, args) {
guild.roles.create({
data: {
name: 'muted',
color: 'RED',
permissions: ["SEND_MESSAGES", "VIEW_CHANNELS"]
},
})
message.channel.send(`${role} created`)
}
}
错误
PS C:\Users\lolzy\OneDrive\Desktop\discordbot> node .
Cbs slave is online!
C:\Users\lolzy\OneDrive\Desktop\discordbot\moderationcommands\muterolecreate.js:9
guild.roles.create({
^
ReferenceError: guild is not defined
at Object.execute (C:\Users\lolzy\OneDrive\Desktop\discordbot\moderationcommands\muterolecreate.js:9:9)
at module.exports (C:\Users\lolzy\OneDrive\Desktop\discordbot\events\guild\message.js:10:26)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20)
at Receiver.receiverOnMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\websocket.js:834:20)
at Receiver.emit (events.js:376:20)
at Receiver.dataMessage (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\receiver.js:437:14)
at Receiver.getData (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\receiver.js:367:17)
at Receiver.startLoop (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\receiver.js:143:22)
at Receiver._write (C:\Users\lolzy\OneDrive\Desktop\discordbot\node_modules\ws\lib\receiver.js:78:10)
PS C:\Users\lolzy\OneDrive\Desktop\discordbot>
2个回答
查看错误内容,而不是默认为混淆。
guild
未定义,因此您需要进行定义。
如果您想要特定公会,请使用
<client>.guilds.cache.get('guildIDHere')
。
如果您想要发送命令的公会,请使用
message.guild
。
Squiddleton
2021-06-23
因此基本上你只需要定义公会。
使用
<client>.guilds.cache.get("GUILD_ID")
const Discord = require("discord.js")
module.exports = {
name: 'muterolecreate',
usage: '%muterolecreate',
discription: "makes a muterole",
execute(client, message, args) {
const guild = client.guilds.cache.get("GUILD_ID")
guild.roles.create({
data: {
name: 'muted',
color: 'RED',
permissions: ["SEND_MESSAGES", "VIEW_CHANNELS"]
},
})
message.channel.send(`${role} created`)
}
}
keution
2021-07-09