如何创建命令来创建角色不和谐机器人

时间:2019-08-29 04:35:45

标签: discord.js

我正在为不和谐而创建一个机器人,我试图在多个地方创建一个能够扮演角色的命令,但我不太了解

git log -S"my expression" aBranch

输入此代码会告诉我“公会未定义” 如果您能帮助我,我将不胜感激

1 个答案:

答案 0 :(得分:0)

您必须定义行会才能在其上调用方法。您可以通过以下几种方式来定义公会并创建角色

  1. 从消息中获取公会
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
}
  1. 从公会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
}

相关问题