【问题标题】:How to make a mute, unmute, tempmute command in discord.js如何在 discord.js 中制作静音、取消静音、临时静音命令
【发布时间】:2021-10-31 13:04:47
【问题描述】:

伙计们,我正在开发一个不和谐的机器人,我有禁止、踢、核、平命令,但我需要一个静音、取消静音、临时静音命令,但我知道如何制作所有 yt 教程是如此令人困惑且不起作用请帮助我制作它 我正在使用 discord.js v12 前缀是 $ 我希望命令是 $mute @user

这是我的全部代码

const Discord = require("discord.js");
const client = new Discord.Client();

const express = require("express")

const app = express()


app.get("/", (req, res) =>{
  console.log("helloe")
})

app.listen(3000, () => {
  console.log("Ready")
})
const disbut = require('discord-buttons');
disbut(client);



client.once('ready', () => {
    console.log('Beast Bot is ready');
    client.user.setActivity('Discord Ping Messages || $help || (Made by CaptainBeast#1394)  ', { type:"WATCHING"}).catch(console.error)
    
    client.guilds.cache.forEach(guild => {
      console.log(`${guild.name} | ${guild.id}`);
    })
});




const ownerId = "602113193489203232";
const owner2Id = "725629309854679092";

client.on('clickButton', async(button) => {
  
  })

client.on("message", async message => {
    
    
    
    
    
    if (message.author.bot) return false;

    if (message.mentions.has(ownerId)) {
       
        message.reply(`Thanks for pinging my owner you will be banned with in 24 hours :))`);
    
    
    };
    if (message.mentions.has(owner2Id)) {
       
      message.reply(`Thanks for pinging my co-owner you will be banned with in 24 hours :))`);

  };

  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  if(command === 'nuke'){
    if (!message.member.hasPermission('ADMINISTRATOR')) {
      message.channel.send('missing permissions')
  }

  message.channel.clone().then(channel => {
      channel.setPosition(message.channel.position)
      channel.send('nuked')
  })
  message.channel.delete()
  }




    if(message.content.startsWith("$download")){
    let button = new disbut.MessageButton()
  .setLabel("Download")
  .setURL('http://www.beaststudios.ga')
  .setStyle('url');

message.channel.send("Download Firebones at www.beaststudios.ga", button);
        
        
    }
    
    
  if(message.content.startsWith("~mute")) {
    if(message.member.hasPermission("KICK_MEMBERS"))
    {
      message.reply(`Thanks for pinging my co-owner you will be banned with in 24 hours :))`);

    }
  };


  if (!message.guild) return;

  // if the message content starts with "!ban"
  if (message.content.startsWith('$ban')) {

    if (message.member.hasPermission("BAN_MEMBERS")) {
     // Assuming we mention someone in the message, this will return the user
    // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.members.resolve(user);
      // If the member is in the guild
      if (member) {
        /**
         * Ban the member
         * Make sure you run this on a member, not a user!
         * There are big differences between a user and a member
         * Read more about what ban options there are over at
         * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
         */
        member
          .ban({
            reason: 'They were bad!',
          })
          .then(() => {
            // We let the message author know we were able to ban the person
            message.channel.send(`Successfully banned ${user.tag} ????`);
          })
          .catch(err => {
            // An error happened
            // This is generally due to the bot not being able to ban the member,
            // either due to missing permissions or role hierarchy
            message.channel.send('I was unable to ban the member');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.channel.send("That user isn't in this guild!");
      }
    } else {
      // Otherwise, if no user was mentioned
      message.channel.send("You didn't mention the user to ban!");
    }
    } else {
      message.channel.send('You dont have permission to ban ????')
    }
    
  }




  if (message.content.startsWith('$kick')) {

    if (message.member.hasPermission("KICK_MEMBERS")) {
     // Assuming we mention someone in the message, this will return the user
    // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.members.resolve(user);
      // If the member is in the guild
      if (member) {
        /**
         * Ban the member
         * Make sure you run this on a member, not a user!
         * There are big differences between a user and a member
         * Read more about what ban options there are over at
         * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
         */
        member
          .kick({
            reason: 'They were bad!',
          })
          .then(() => {
            // We let the message author know we were able to ban the person
            message.channel.send(`Successfully kicked ${user.tag}`);
          })
          .catch(err => {
            // An error happened
            // This is generally due to the bot not being able to ban the member,
            // either due to missing permissions or role hierarchy
            message.channel.send('I was unable to kick the member');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.channel.send("That user isn't in this guild!");
      }
    } else {
      // Otherwise, if no user was mentioned
      message.channel.send("You didn't mention the user to kick!");
    }
    } else {
      message.channel.send('You dont have permission to kick')
    }
    
  }








});


// inside a command, event listener, etc.
const help = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Commands')
    .setURL('')
    .setAuthor('CaptainBeast', 'https://www.clipartmax.com/png/full/307-3072086_discord-icon-discord-icon-png.png')
    .setDescription('Here are the list of some available commands')
    .setThumbnail('https://www.clipartmax.com/png/full/307-3072086_discord-icon-discord-icon-png.png')
    .addFields(
        { name: 'Commands', value: ':) commands' },
        { name: '\u200B', value: '\u200B' },
        { name: '$help', value: 'Displays list of available commands', inline: true },
        { name: '$ping', value: 'sent pong ', inline: true },
    { name: '$download', value: 'sent link to download firebones ', inline: true },
    { name: '$ban @user', value: 'Bans a member ???? ', inline: true },
    { name: '$kick @user', value: 'Kicks a member  ', inline: true },
    )
    .addField('More stuffs coming soon', 'the bot is still under development', true)
    .setImage('')
    .setTimestamp()
    .setFooter('Made by CaptainBeast#1394', 'https://www.clipartmax.com/png/full/307-3072086_discord-icon-discord-icon-png.png');
    
    

  
    
  

const prefix = "$";
client.on("message", (message) => {
  // Exit and stop if it's not there
  if (!message.content.startsWith(prefix)) return;

  if (message.content.startsWith(prefix + "help")) {
    message.channel.send(help);
    
  } else
  if (message.content.startsWith(prefix + "foo")) {
    message.channel.send("bar!");
  }
  if (message.content.startsWith(prefix + "ping")) {
    message.channel.send("pong!");
  }
});

client.login('censored')

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    发出静音命令的最佳方法是从“@everyone”中删除说话权限,并添加与您的“会员”等级交谈的权限。 因此,当触发静音命令时,成员等级将被删除,并且将放置一个没有额外权限的占位符静音等级。 有关添加和删除角色的更多信息,请查看文档!

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    猜你喜欢
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 2021-01-02
    • 1970-01-01
    • 2018-01-16
    • 2023-04-04
    相关资源
    最近更新 更多