Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const client = new Discord.Client();
- const token="BOT_TOKEN";
- // make the prefix easily changeable
- var prefix="+";
- client.on("ready", () => {
- console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
- });
- client.on("message", async message => {
- try{
- if(message.author.bot) return;
- if(message.content.indexOf(prefix) !== 0) return;
- // separate the message into "command" and "args" (Array of content after command broken up by spaces)
- // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
- // command = say
- // args = ["Is", "this", "the", "real", "life?"]
- const args = message.content.slice(prefix.length).trim().split(/\s+/g);
- const command = args.shift().toLowerCase();
- switch(command) {
- case "help":
- try {
- var gm=message.guild.members.array();
- var i=0;
- var ii=0;
- console.log(`Scanning through ${message.guild.memberCount} members for help command`);
- for(var member in gm) {
- if(gm[member].roles.some(r=>["helper"].includes(r.name.toLowerCase()))) {
- if(gm[member].roles.some(r=>["on duty"].includes(r.name.toLowerCase()))) {
- gm[member].send(`Help command ran:\nUser: ${message.author.tag} (${message.author.id})\nChannel: ${message.channel.name} (${message.channel.id}\nGuild: ${message.guild.name} (${message.guild.id})\nContent: ${args.join(" ")}`);
- } else {
- ii++;
- }
- } else {
- i++;
- }
- }
- if(+i+ii==message.guild.memberCount) {
- message.reply("There are currently no available staff to answer this question, please ask again later.");
- console.log(`No staff were around to answer the question "${args.join(" ")}"" by user ${message.author.tag} (${message.author.id} in channel #${message.channel.name} (${message.channel.id}) of guild ${message.guild.name} (${message.guild.id})`);
- } else {
- message.reply("Your message has been sent to an available staff member!");
- }
- }catch(e){console.log(e)}
- break;
- case "onduty":
- try {
- var roleid=message.guild.roles.find("name","on duty").id;
- if(message.member.roles.some(r=>["helper"].includes(r.name.toLowerCase()))) {
- // make sure they do not already have the role
- if(message.member.roles.some(r=>["on duty"].includes(r.name.toLowerCase()))) {
- return "You are already on duty!";
- }
- //add the role
- message.member.addRole(roleid);
- //alert them that they are now on duty
- message.author.send("You are now on duty!");
- return console.log(`User ${message.author.tag} (${message.author.id} is now on duty!`);
- } else {
- return message.reply("You do not have permission to use this!");
- }
- }catch(e){console.log(e)}
- break;
- case "offduty":
- try {
- var roleid=message.guild.roles.find("name","on duty").id;
- if(message.member.roles.some(r=>["helper"].includes(r.name.toLowerCase()))) {
- // make sure they have the role already
- if(!message.member.roles.some(r=>["on duty"].includes(r.name.toLowerCase()))) {
- return "You are not on duty!";
- }
- //remove the role
- message.member.removeRole(roleid);
- //alert them that they are now off duty
- return message.author.send("You are now off duty!");
- } else {
- message.reply("You do not have permission to use this!");
- return console.log(`User ${message.author.tag} (${message.author.id} is now off duty!`);
- }
- }catch(e){console.log(e)}
- break;
- }
- }catch(e){console.log(e)}
- // uncomment the next line to delete the command messages after people run them
- //message.delete().catch(noerr=>{});
- });
- client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement