如何解决“提供的参数既不是用户也不是角色”。

时间:2019-05-06 07:14:12

标签: discord.js commando

我正在尝试使机器人扮演角色,并在命令的参数中转到指定的通道。
代码将使机器人进入指定的通道,并为该机器人刚刚担任的角色添加权限,这就是问题所在。
VSC中的控制台显示“未指定角色/用户” ,并且跳过了该操作。

我尝试将arole更改为var,并将arolemessage.arole)设置为arole.id,但仍然无法使用。乱搞和更改设置根本不起作用。

let woaID = message.mentions.channels.first();
if (!woaID) return message.channel.send("Channel is nonexistant or command was not formatted properly. Please do s!woa #(channelname)");
let specifiedchannel = message.guild.channels.find(t => t.id == woaID.id);
var arole = message.guild.createRole({
  name: `A marker v1.0`,
  color: 0xcc3b3b,
  hoist: false,
  mentionable: false,
  permissions: ['SEND_MESSAGES']
}).catch(console.error);

message.channel.send("Created role...");

message.channel.send("Role set up...");


/*const sbwrID = message.guild.roles.find(`null v1.0`);
let specifiedrole = message.guild.roles.find(r => r.id == sbwrID.id)*/

message.channel.send('Modified');

specifiedchannel.overwritePermissions(message.arole, {
    VIEW_CHANNEL: true,
    SEND_MESSAGES: false
  })
  .then(updated => console.log(updated.permissionOverwrites.get(arole.id)))
  .catch(console.error);

我希望该漫游器能够访问args中的指定通道,并创建角色并覆盖该通道的角色权限。

实际输出是该漫游器可以正常运行,但该角色对该通道没有特殊权限。

1 个答案:

答案 0 :(得分:0)

您的代码有两个主要问题:

  • Guild.createRole()不会同步返回Role:它会返回Promise<Role>,因此实际上您没有提供.overwritePermissions()的自变量角色
  • 创建角色后(如果将其正确存储在arole中),您将不能以message.arole的身份访问它。

您可以使用async/await或使用.then() Promise方法来实现。
如果您对诺言或异步代码不满意,则应该尝试学习有关它的知识,这真的很有用:查看MDN的Using promisesPromiseasync function文档。

这是一个例子:

message.guild.createRole({
  name: `A marker v1.0`,
  color: 0xcc3b3b,
  hoist: false,
  mentionable: false,
  permissions: ['SEND_MESSAGES']
}).then(async arole => {
  let updated = await specifiedchannel.overwritePermissions(arole, {
    VIEW_CHANNEL: true,
    SEND_MESSAGES: false
  });
  console.log(updated.permissionOverwrites.get(arole.id));
}).catch(console.error);
相关问题