Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

discord - What's the prefix for mute

Problems with my bot. Can't get mute to work. Help? Can't find any prefix and don't know where to add it or how to format it. I linked most of code below. Anti-spam and kick/ban works. New to coding to any help would be nice. Tips how set a general prefix for all code foward? Role is named mute and bot has all premissons it shall need to kick

const fs = require('fs');
module.exports = class mute {
    constructor(){
        this.name = 'mute',
        this.alias = ['tempmute'],
        this.usage = 'mute';
    }

    run(bot, message, args){
        let member = message.mentions.members.first();

        var command = args[0];
        var mentioned = args[1];

        var days = parseInt(args[3]);
        var hours = parseInt(args[4]);
        var seconds = parseInt(args[5]);

        if (message.member.hasPermission('MANAGE_ROLES')) {

        let muterole = message.guild.roles.find(role => role.name === "Muted");

        if (!message.guild) {
        if (message.guild.id === '505872328538718233') {
            let memberrole = message.guild.roles.find("name", "Member");
            member.removeRole(memberrole);

        }}

        let usermsg = new Discord.RichEmbed();

        usermsg.setTitle('You have been Muted.');
        usermsg.setColor('76b3fc');
        usermsg.setFooter('Please do not attempt to bypass');
        usermsg.addField('Muted by:',
        `<@${message.author.id}>`);
        
        let mutedmsg = new Discord.RichEmbed();
    
        mutedmsg.setTitle('User has been Muted Successfully');
        mutedmsg.setColor('76b3fc');
        mutedmsg.setDescription(`User muted: ${mentioned}
Muted by: <@${message.author.id}>
Reason: ${input}`);
        mutedmsg.setFooter('This mute has been logged.');

        if (message.content === `${command}`) {
            return message.channel.send('You did not provide a member to mute.');
        }
        
        if (message.content === `${command} ${mentioned}`) {
        return message.channel.send('Please input a reason for the mute.');
        }

        if (message.guild.roles.find(role => role.name)) {

        message.member.addRole(muterole);

            if (message.content.includes (`${days}d`)) {
                message.channel.send(mutedmsg);
            setTimeout(() => {
                member.removeRole(muterole);
                usermsg.addField('Punishment Time:',
                 `${hours} Seconds`);
            }, `${args[2]} * 86400`);
        }

            if (message.content.includes (`${hours}h`)) {
                message.channel.send(mutedmsg);
            setTimeout(() => {
                member.removeRole(muterole);
                usermsg.addField('Punishment Time:',
                 `${hours} Seconds`);
            }, `${args[3]} * 3600`);
        }

            if (message.content.includes (`${seconds}s`)) {
                message.channel.send(mutedmsg);
            setTimeout(() => {
                member.removeRole(muterole);
                usermsg.addField('Punishment Time:',
                 `${seconds} Seconds`);
            }, `${args[4]} * 1000`);
        }

        if (message.content === `${command} ${mentioned} ${input}`) {
            message.member.addRole(muterole);
            usermsg.addField('Muted for',
            `${input}`);
            usermsg.addField('Punishment Time:',
            'Permenant');
            message.channel.send(mutedmsg);
        }

        if (message.member.id === `${message.author.id}`) {
            return;
        }
        if (message.author.id === `${mentioned}`) {
            return message.member.send(usermsg);
        }
    
        message.channel.send(mutedmsg);
        console.log('===========================');
        console.log(`Member Muted: ${mentioned}`);
        console.log(`Muted by: ${message.author.tag}`);
        console.log(`Reason: ${input}`);
        console.log('===========================');
    } else {

        message.channel.send('You do not have a `Muted` Role, This command won't work.');
    }

    } else {

        message.reply('You do not have permission to do this.');

    }

let jsonlogs = JSON.parse(fs.writeFileSync("./storages/mutelogs.json"));

if (!jsonlogs[message.guild.id]){
    jsonlogs[message.guild.id] = {
        mutedby: `${message.author.tag}`,
        user: `${mentioned}`,
        reason: `${input}`,
        days: `${days}`,
        hours: `${hours}`,
        seconds: `${seconds}`,
    };
}
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You seem to have a lot, and I mean A LOT of outdated methods from Discord.js v11.

I'd highly recommend installing the newest version of DJS and reading all of the v12 changes that can be found here: https://github.com/discordjs/discord.js/releases/tag/12.0.0

Some examples:

  • Discord.RichEmbed() no longer exists -> Use Discord.MessageEmbed()
  • .addRole() no longer exists -> Use message.member.roles.add()
  • .removeRole() no longer exists -> Use message.member.roles.remove()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...