Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

discord js give role to all member

// find the role with the name "Community"
let role = message.guild.roles.find(r => r.name == 'Community')

// if role doesn't exist, notify the author of command that the role couldn't be found
if (!role) return message.channel.send(`**${message.author.username}**, role not found`)

// find all guild members that aren't bots, and add the "Community" role to each
message.guild.members.filter(m => !m.user.bot).forEach(member => member.addRole(role))

// notify the author of the command that the role was successfully added to all members
message.channel.send(`**${message.author.username}**, role **${role.name}** was added to all members`)
Comment

discord.js give role command

bot.on('message', (message) => {
    if (!message.content.startsWith(PREFIX) || message.author.bot) return;

    const args = message.content
        .toLowerCase()
        .slice(PREFIX.length)
        .trim()
        .split(/s+/);
    const [command, input] = args;

    if (command === 'clear' || command === 'c') {
        if (!message.member.hasPermission('MANAGE_MESSAGES')) {
            return message.channel
                .send(
                    "Sorry, ale nemáš na to dostatečná práva (`MANAGE_MESSAGES`) :shield: ",
                );
        }

        if (isNaN(input)) {
            return message.channel
                .send('Napiš kolik zpráv mám smazat :eyes: ')
                .then((sent) => {
                    setTimeout(() => {
                        sent.delete();
                    }, 2500);
                });
        }

        if (Number(input) < 0) {
            return message.channel
                .send('Brácho .... rozumím, nemažu nic :clown: ')
                .then((sent) => {
                    setTimeout(() => {
                        sent.delete();
                    }, 2500);
                });
        }

        // add an extra to delete the current message too
        const amount = Number(input) > 100 ?
            101 :
            Number(input) + 1;

        message.channel.bulkDelete(amount, true)
            .then((_message) => {
                message.channel
                    // do you want to include the current message here?
                    // if not it should be ${_message.size - 1}
                    .send(`Smazal jsem `${_message.size}` zpráv :broom:`)
                    .then((sent) => {
                        setTimeout(() => {
                            sent.delete();
                        }, 2500);
                    });
            });
    }

    if (command === 'help' && input === 'clear') {
        const embed = new Discord.MessageEmbed()
            .setColor('#00B2B2')
            .setTitle('**Clear Help**')
            .setDescription(
                `Tento příkaz maže správy. Například takto: `${PREFIX}clear 5` nebo `${PREFIX}c 5`.`,
            )
            .setFooter(
                `Vyžádáno uživatelem: ${message.author.tag}`,
                message.author.displayAvatarURL(),
            )
            .setTimestamp();

        message.channel.send(embed);
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: break loop timeout javascript 
Javascript :: javascript remove last word from string 
Javascript :: jquery datepicker disable dates dynamically 
Javascript :: arrow function syntax vs function expression syntax 
Javascript :: where to create service angularor nodejs 
Javascript :: pattern printing in javascript 
Javascript :: window open method for browser detection 
Javascript :: in express how do you set the location header 
Javascript :: hasOwnProperty.call js 
Javascript :: discord js people in voice channel 
Javascript :: useeffect loading state 
Javascript :: solid in css 
Javascript :: vue js multiple dynamic classes 
Javascript :: convert excel date to javascript date 
Javascript :: array reverse with for loop 
Javascript :: he valid characters are defined in rfc 7230 and rfc 3986 
Javascript :: what would (int) (Math.random()) output 
Javascript :: nextjs use dotnenv 
Javascript :: function l(){return window.performance 
Javascript :: loop number in react 
Python :: python get public ip address 
Python :: seaborn figsize 
Python :: pandas see all columns 
Python :: python exception with line number 
Python :: python get current directory 
Python :: python selenium go back 
Python :: install imageio 
Python :: python check if has attribute 
Python :: for loop django template count 
Python :: python how to count the lines in a file 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =