久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord.js 靜音命令僅發(fā)送不正確命令的嵌入

Discord.js Mute command only sends embed for incorrect command(Discord.js 靜音命令僅發(fā)送不正確命令的嵌入)
本文介紹了Discord.js 靜音命令僅發(fā)送不正確命令的嵌入的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

所以我為我的不和諧機器人發(fā)出了靜音命令,它會發(fā)現(xiàn)是否靜音".角色存在,如果不存在,則機器人創(chuàng)建一個靜音"角色.角色,然后將該角色賦予提到的成員,當前當我運行命令時,它只會給我嵌入,如果命令編寫不正確,它應(yīng)該發(fā)送.

So im making a mute command for my discord bot which finds if a "Muted" role exists and if it doesn't then the bot creates a "Muted" role and then gives that role to the mentioned member and currently when i run the command it only gives me the embed that its supposed to send if the command was written incorrectly.

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.
You cannot mute me.
You cannot mute members with a role higher than yours
You cannot mute members that have already been muted'}
   )
    .setFooter(client.user.tag, client.user.displayAvatarURL());

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

    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 (muterole = undefined) 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).catch(err => console.log(err).then(message.channel.send('There was an error while muting the member')))

  } 
}

我仍然無法找出問題所在以及為什么會這樣,我非常想知道我的代碼中的錯誤以及是否還有其他我不知道的錯誤.

I am still unable to find out what the problem is and why it does this, i would very much like to know the error in my code and if there are any more erros that i am unaware of.

推薦答案

我們可以看到你的代碼:

We can see your code:


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

if (muterole = undefined) return message.channel.send(Embedhelp);

這將在未定義 muterole 時停止運行.由于 muterole 無法創(chuàng)建,它會在運行到 if muterole 行時停止運行.為了解決這個問題,在 discord.js 中創(chuàng)建角色時,僅當您要為角色添加權(quán)限時才需要權(quán)限標志.您不必將 false/deny 指定為您不希望角色中的特定權(quán)限,因為如果您不將它們標記出來,它會將所有權(quán)限標記為 false.因此,我們可以只用括號替換權(quán)限:

and this will stop the runnning while muterole is undefined. Since the muterole is not able to create, it will stop running while running to the if muterole line. To fix the problem, while creating a role in discord.js, permissions flag is needed only when you want to add the permissions to the role. You don't have to put false/deny to specific which permissions you don't want in the role since it's marking all the permissions as false if you don't't label them out. Therefore, we could replace the permissions with only bracket:

if (muterole === undefined) {
    message.guild.roles.create({
        data: {
            name: 'muted',
            color: '#ff0000',
            permissions: []
        },
        reason: 'to mute people',
    })
        .catch(err => console.log(err).then(message.channel.send('Mute Role could not be created')))
}

這篇關(guān)于Discord.js 靜音命令僅發(fā)送不正確命令的嵌入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發(fā)出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 国产91久久精品一区二区 | 91精品在线播放 | 91精品国产综合久久久动漫日韩 | 日韩欧美国产一区二区三区 | 91色网站 | 国产成人精品在线 | 国产一区在线看 | 精品国产精品三级精品av网址 | 午夜tv免费观看 | 亚洲精品一二三区 | 亚洲国产成人精品女人久久久野战 | 日韩免费电影 | 日本三级电影免费 | 女人毛片a毛片久久人人 | 精品国产一区二区三区性色av | 中文字幕成人网 | 亚洲精品久久久久久久久久久 | 亚洲国内精品 | 最新中文字幕在线播放 | 国产99久久精品一区二区300 | 国产精品成人一区二区三区 | 久久精品综合 | 成人网av | 在线免费观看a级片 | 欧美一极视频 | 三级在线视频 | 人人爽日日躁夜夜躁尤物 | 国产精品一区二区三区四区 | 美女爽到呻吟久久久久 | 午夜电影合集 | 国产一级片网站 | 日韩在线不卡 | 亚洲一区中文字幕 | 99pao成人国产永久免费视频 | 国产精品成人一区 | 欧美精品1区 | 亚洲欧洲视频 | 国产精品亚洲成在人线 | aaaa日韩| av影音资源 | 欧美精品一区二区三区四区 在线 |