discord.js - 如何创建命令创建角色 | 不和谐机器人
问题描述
我正在为不和谐创建一个机器人,我尝试创建一个能够发挥作用的命令,已经在几个地方,但我不能很好地理解它
guild.createRole({
name: 'role',
color: 'RED'
});
把这段代码告诉我“公会没有定义”如果你能帮助我,我将不胜感激
解决方案
You have to define the guild to be able to call methods on it. Here are a few ways you can define the guild and create a role
- Retrieve the guild from a message
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', (message) => {
let guild = message.guild;
guild.createRole(...) ///put in your data here
.then(role => console.log(`Created new role with name ${role.name}`)) //What to do when it has been created
.catch(console.error); //Handle an error
}
- Get the guild from guild id
const Discord = require('discord.js');
const client = new Discord.Client();
client.on("ready", () => {
let guild = client.guilds.get("GUILD-ID"); //Replace "GUILD-ID" with the id of the guild you want
guild.createRole(...) ///put in your data here
.then(role => console.log(`Created new role with name ${role.name}`)) //What to do when it has been created
.catch(console.error); //Handle an error
}
推荐阅读
- css - 将 div 预加载器覆盖到部分元素
- javascript - ElectronJS - 使用本地键盘快捷键在 Teaxtarea 中制作粗体文本
- java - 使用 jnativehook 库 Maven JAR 创建 jar 时出现问题
- jquery - 使用 CSS、ajax 和 jQuery 将新行添加到 div 生成的表中
- objective-c++ - 如何停止()主线程 NSApp run()事件循环?(嵌入在 C++ 中)
- c - C语言指针相关问题
- extjs - 如何知道视图模型中的数据是否已更改?
- javascript - 未捕获的类型错误:无法读取未定义的属性“框架”-PHASER3
- react-native - 更改边框颜色文本输入当它在反应原生时为空
- javascript - 如果我需要按 {entry.heat) 排序,beolw JS 的排序如何?