Discord.js错误提供的角色不是角色,雪花或数组或角色或雪花的集合 [英] Discord.js Error Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes

查看:82
本文介绍了Discord.js错误提供的角色不是角色,雪花或数组或角色或雪花的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的机器人创建一个静音命令,如果没有该角色,它将创建一个静音角色,并将该角色提供给命令中提到的用户,当前错误消息是;

I'm making a mute command for my bot where it creates a muted role if there isn't one already and gives it to the user that is mentioned in the command, currently the error im getting is;

[INVALID_TYPE]:提供的角色不是角色,雪花或数组或角色或雪花的集合.

我最好的猜测是,发生此错误是因为它没有创建应该为其创建的角色,因此无法将其赋予所提到的成员,但是我可能完全错了.

My best guess is that this error occurs because it doesn't create the role that it is supposed to create therefor it cannot give it to the mentioned member, i may be completely wrong though.

const BaseCommand = require('../../utils/structures/BaseCommand');
const Discord = require('discord.js');

module.exports = class MuteCommand extends BaseCommand {
  constructor() {
    super('mute', 'moderation', []);
  }

  async run(client, message, args) {
    if(!message.member.hasPermission("MUTE_MEMBERS")) return message.channel.send("You do not have Permission to use this command.");
    if(!message.guild.me.hasPermission("MUTE_MEMBERS")) return message.channel.send("I do not have Permissions to mute members.");
    const Embedhelp = new Discord.MessageEmbed()
    .setTitle('Mute Command')
    .setColor('#6DCE75')
    .setDescription('Use this command to Mute a member so that they cannot chat in text channels nor speak in voice channels')
    .addFields(
      { name: '**Usage:**', value: '=mute (user) (time) (reason)'},
      { name: '**Example:**', value: '=mute @Michael stfu'},
      { name: '**Info**', value: 'You cannot mute yourself.\nYou cannot mute me.\nYou cannot mute members with a role higher than yours\nYou cannot mute members that have already been muted'}
   )
    .setFooter(client.user.tag, client.user.displayAvatarURL());

    let role = 'muted' || 'Muted';
    let newrole = message.guild.roles.cache.find(x => x.name === role);
    if (typeof newrole === undefined) {
      message.guild.roles.create({
        data: {
          name: 'Muted',
          color: '#ff0000',
          permissions: {
              SEND_MESSAGES: false,
              ADD_REACTIONS: false,
              SPEAK: false
          }
        },
        reason: 'to mute people',
      })
      .catch(console.log(err)); {
        message.channel.send('Could not create muted role');
      };
    };
    let muterole = message.guild.roles.cache.find(x => x.name === role);

    const mentionedMember = message.mentions.members.first() || await message.guild.members.fetch(args[0]);
    let reason = args.slice(1).join(" ");
    const banEmbed = new Discord.MessageEmbed()
     .setTitle('You have been Muted in '+message.guild.name)
     .setDescription('Reason for Mute: '+reason)
     .setColor('#6DCE75')
     .setTimestamp()
     .setFooter(client.user.tag, client.user.displayAvatarURL());

   if (!reason) reason = 'No reason provided';
   if (!args[0]) return message.channel.send(Embedhelp);
   if (!mentionedMember) return message.channel.send(Embedhelp);
   if (!mentionedMember.bannable) return message.channel.send(Embedhelp);
   if (mentionedMember.user.id == message.author.id) return message.channel.send(Embedhelp);
   if (mentionedMember.user.id == client.user.id) return message.channel.send(Embedhelp);
   if (mentionedMember.roles.cache.has(muterole)) return message.channel.send(Embedhelp);
   if (message.member.roles.highest.position <= mentionedMember.roles.highest.position) return message.channel.send(Embedhelp);

   await mentionedMember.send(banEmbed).catch(err => console.log(err));
   await mentionedMember.roles
  .add(muterole)
  .then(() => message.channel.send("There was an error while muting the member"))
  .catch((err) => console.log(err));

  } 
}

创建角色的代码行是:

message.guild.roles.create({
        data: {
          name: 'Muted',
          color: '#ff0000',
          permissions: {
              SEND_MESSAGES: false,
              ADD_REACTIONS: false,
              SPEAK: false
          }
        },
        reason: 'to mute people',
      })

推荐答案

您可以使用async/await或.then,但我建议使用async/await.例如:

You can use either async/await or .then, but i recommend using async/await. For example:


const mentionedMember = message.mentions.members.first() || await 
message.guild.members.fetch(args[0]);

const newMutedRole = await message.guild.roles.create({
        data: {
          name: 'Muted',
          color: '#ff0000',
          permissions: {
              SEND_MESSAGES: false,
              ADD_REACTIONS: false,
              SPEAK: false
          }
        },
        reason: 'to mute people',
      })


mendtionedMember.roles.add(newMutedRole)

这篇关于Discord.js错误提供的角色不是角色,雪花或数组或角色或雪花的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆