Basic Setup
This commit is contained in:
parent
5d21b40edf
commit
2e3aeaed24
12 changed files with 863 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -102,3 +102,5 @@ dist
|
|||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
config.json
|
5
bot.js
Normal file
5
bot.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const vylbot = require('vylbot-core');
|
||||
const config = require('./config.json');
|
||||
|
||||
const client = new vylbot.client(config);
|
||||
client.start();
|
43
commands/about.js
Normal file
43
commands/about.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Required components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class about extends command {
|
||||
constructor() {
|
||||
// Set execute method, description, and category
|
||||
super("about");
|
||||
super.description = "About the bot";
|
||||
super.category = "General";
|
||||
|
||||
// Set required configs in the config.about json string.
|
||||
// description: The bot description
|
||||
// version: The bot version
|
||||
// author: Bot author
|
||||
// date: Date of build
|
||||
super.requiredConfigs = "description";
|
||||
super.requiredConfigs = "version";
|
||||
super.requiredConfigs = "author";
|
||||
super.requiredConfigs = "date";
|
||||
}
|
||||
|
||||
// The execution method
|
||||
about(context) {
|
||||
// Create an embed containing data about the bot
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle("About")
|
||||
.setColor(embedColor)
|
||||
.setDescription(context.client.config.about.description)
|
||||
.addField("Version", context.client.config.about.version)
|
||||
.addField("Author", context.client.config.about.author)
|
||||
.addField("Date", context.client.config.about.date);
|
||||
|
||||
// Send embed to the channel the command was sent in
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the about class to be exported
|
||||
module.exports = about;
|
93
commands/ban.js
Normal file
93
commands/ban.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Required components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class ban extends command {
|
||||
constructor() {
|
||||
// Set execution method, description, category, and usage
|
||||
super("ban");
|
||||
super.description = "Bans the mentioned user with an optional reason";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<@user> [reason]";
|
||||
|
||||
// Set required configs in the config.ban json string
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredCofigs = "logchannel";
|
||||
}
|
||||
|
||||
// Command execution method
|
||||
ban(context) {
|
||||
// If the user has the modrole (set in config.ban.modrole)
|
||||
if (context.message.guild.roles.cache.find(role => role.name == context.client.config.ban.modrole)) {
|
||||
// Gets the user pinged in the command
|
||||
let user = context.message.mentions.users.first();
|
||||
|
||||
// If the user pinged is a valid user
|
||||
if (user) {
|
||||
// Get the guild member object from the pinged user
|
||||
let member = context.message.guild.member(user);
|
||||
|
||||
// If the member object exists, i.e. if they are in the server
|
||||
if (member) {
|
||||
// Get the arguments and remove what isn't the reason
|
||||
let reasonArgs = context.arguments;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
// Join the array into a string
|
||||
let reason = reasonArgs.join(" ");
|
||||
|
||||
// If the guild is available to work with
|
||||
if (context.message.guild.available) {
|
||||
// If the bot client is able to ban the member
|
||||
if (member.bannable) {
|
||||
// The Message Embed which goes into the bot log
|
||||
let embedLog = new MessageEmbed()
|
||||
.setTitle("Member Banned")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${user} \`${user.tag}\``, true)
|
||||
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
||||
.addField("Reason", reason || "*none*")
|
||||
.setThumbnail(user.displayAvatarURL);
|
||||
|
||||
// The Message Embed which goes into the public channel the message was sent in
|
||||
let embedPublic = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${user} has been banned`);
|
||||
|
||||
// Ban the member and send the embeds into the appropriate channel, then delete the initial message
|
||||
member.ban({ reason: reason }).then(() => {
|
||||
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.ban.logchannel).send(embedLog);
|
||||
context.message.channel.send(embedPublic);
|
||||
|
||||
context.message.delete();
|
||||
}).catch(err => { // If the bot couldn't ban the member, say so and log the error to the console
|
||||
errorEmbed(context, "An error occurred");
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else { // If the member object doesn't exist
|
||||
errorEmbed(context, "User is not in this server");
|
||||
}
|
||||
} else { // If the user object doesn't exist
|
||||
errorEmbed(context, "User does not exist");
|
||||
}
|
||||
} else { // If the user doesn't have the mod role
|
||||
errorEmbed(context, `You require the \`${context.client.config.ban.modrole}\` role to run this command`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Post an error embed
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = ban;
|
58
commands/clear.js
Normal file
58
commands/clear.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
// Required components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class clear extends command {
|
||||
constructor() {
|
||||
// Set execute method, description, category, and usage
|
||||
super("clear");
|
||||
super.description = "Bulk deletes the chat for up to 100 messages";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<amount>";
|
||||
|
||||
// Set required configs in the config.clear json string
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredConfigs = "logchannel";
|
||||
}
|
||||
|
||||
// Execute method
|
||||
clear(context) {
|
||||
// If the user has the config.clear.modrole role
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.clear.modrole)) {
|
||||
// If the command specifies a number between 1 and 100
|
||||
if (context.arguments.length > 0 && context.arguments[0] > 0 && context.arguments[0] < 101) {
|
||||
// Attempt to bulk delete the amount of messages specified as an argument
|
||||
context.message.channel.bulkDelete(context.arguments[0]).then(() => {
|
||||
// Public embed
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${context.arguments[0]} messages were removed`);
|
||||
|
||||
// Send the embed into the channel the command was sent in
|
||||
context.message.channel.send(embed);
|
||||
}).catch(err => { // If the bot couldn't bulk delete
|
||||
errorEmbed(context, "An error has occurred");
|
||||
console.log(err);
|
||||
});
|
||||
} else { // If the user didn't give a number valid (between 1 and 100)
|
||||
errorEmbed(context, "Please specify an amount between 1 and 100");
|
||||
}
|
||||
} else { // If the user doesn't have the mod role
|
||||
errorEmbed(context, `This command requires the \`${context.client.config.clear.modrole}\` role to run`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to send an error embed
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = clear;
|
150
commands/help.js
Normal file
150
commands/help.js
Normal file
|
@ -0,0 +1,150 @@
|
|||
// Required Components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { readdirSync } = require('fs');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class help extends command {
|
||||
constructor() {
|
||||
// Set the execute method, description, category, and example usage
|
||||
super("help");
|
||||
super.description = "Gives a list of commands available in the bot";
|
||||
super.category = "General";
|
||||
super.usage = "[command]";
|
||||
}
|
||||
|
||||
// Execute method
|
||||
help(context) {
|
||||
// Get the list of command folders the bot has been setup to check
|
||||
let commandFolders = context.client.config.commands;
|
||||
|
||||
// Empty arrays for commands
|
||||
// allCommands: Will contain objects of all commands with their related info
|
||||
// categories: Will contain strings of all the categories the commands are set to, unique
|
||||
let allCommands = [];
|
||||
let categories = [];
|
||||
|
||||
// Loop through all the command folders set
|
||||
// i = folder index
|
||||
for (let i = 0; i < commandFolders.length; i++) {
|
||||
// The current folder the bot is looking through
|
||||
let folder = commandFolders[i];
|
||||
|
||||
// Read the directory of the current folder
|
||||
let contents = readdirSync(`${process.cwd()}/${folder}`);
|
||||
|
||||
// Loop through the contents of the folder
|
||||
// j = file index in folder i
|
||||
for (let j = 0; j < contents.length; j++) {
|
||||
// Get command in the current folder to read
|
||||
let file = require(`${process.cwd()}/${folder}/${contents[j]}`);
|
||||
|
||||
// Initialise the command
|
||||
let obj = new file();
|
||||
|
||||
// Data object containing the command information
|
||||
let data = {
|
||||
"name": contents[j].replace(".js", ""),
|
||||
"description": obj.description,
|
||||
"category": obj.category,
|
||||
"usage": obj.usage,
|
||||
"roles": obj.roles
|
||||
};
|
||||
|
||||
// Push the command data to the allCommands Array
|
||||
allCommands.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
// Loop through all the commands discovered by the previous loop
|
||||
for (let i = 0; i < allCommands.length; i++) {
|
||||
// Get the current command category name, otherwise "none"
|
||||
let category = allCommands[i].category || "none";
|
||||
|
||||
// If the command isn't already set, set it.
|
||||
// This will then make the categories array be an array of all categories which have been used but only one of each.
|
||||
if (!categories.includes(category)) categories.push(category);
|
||||
}
|
||||
|
||||
// If an command name has been passed as an argument
|
||||
// If so, send information about that command
|
||||
// If not, send the help embed of all commands
|
||||
if (context.arguments[0]) {
|
||||
sendCommand(context, allCommands, context.arguments[0]);
|
||||
} else {
|
||||
sendAll(context, categories, allCommands);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send embed of all commands
|
||||
// context: The command context json string
|
||||
// categories: The array of categories found
|
||||
// allCommands: The array of the commands found
|
||||
function sendAll(context, categories, allCommands) {
|
||||
// Embed to be sent
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setTitle("Commands");
|
||||
|
||||
// Loop through each command
|
||||
for (let i = 0; i < categories.length; i++) {
|
||||
// The category name of the current one to check
|
||||
let category = categories[i];
|
||||
|
||||
// Empty Array for the next loop to filter out the current category
|
||||
let commandsFilter = [];
|
||||
|
||||
// Loop through allCommands
|
||||
// If the command is set to the current category being checked, add it to the filter array
|
||||
for (let j = 0; j < allCommands.length; j++) {
|
||||
if (allCommands[j].category == category) commandsFilter.push(`\`${allCommands[j].name}\``);
|
||||
}
|
||||
|
||||
// Add a field to the embed which contains the category name and all the commands in that category
|
||||
embed.addField(category, commandsFilter.join(", "));
|
||||
}
|
||||
|
||||
// Send the embed
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
// Send information about a specific command
|
||||
// context: The command context json string
|
||||
// allCommands: The array of categories found
|
||||
// name: The command name to check
|
||||
function sendCommand(context, allCommands, name) {
|
||||
let command = {};
|
||||
|
||||
// Loop through all commands, if the command name is the same as the one we're looking for, select it
|
||||
for (let i = 0; i < allCommands.length; i++) {
|
||||
if (allCommands[i].name == name) command = allCommands[i];
|
||||
}
|
||||
|
||||
// If a matching command has been found
|
||||
if (command.name) {
|
||||
// Create an embed containing the related information of the command
|
||||
// The title is the command name but sets the first letter to be capitalised
|
||||
// If a set of information isn't set, set it to say "none"
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setTitle(command.name[0].toUpperCase() + command.name.substring(1))
|
||||
.setDescription(command.description || "*none*")
|
||||
.addField("Category", command.category || "*none*", true)
|
||||
.addField("Usage", command.usage || "*none*", true)
|
||||
.addField("Required Roles", command.roles.join(", ") || "*none*");
|
||||
|
||||
// Send the embed
|
||||
context.message.channel.send(embed);
|
||||
} else { // If no command has been found, then send an embed which says this
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription("Command does not exist");
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = help;
|
93
commands/kick.js
Normal file
93
commands/kick.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Required Components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class kick extends command {
|
||||
constructor() {
|
||||
// Sets the command's run method, description, category, and usage
|
||||
super("kick");
|
||||
super.description = "Kicks the mentioned user with an optional reason";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<@user> [reason]";
|
||||
|
||||
// Sets the required configs for the command
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredConfigs = "logchannel";
|
||||
}
|
||||
|
||||
// The command's run method
|
||||
kick(context) {
|
||||
// Checks if the user has the mod role, set in the config json string
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.kick.modrole)) {
|
||||
// Gets the first user pinged in the command
|
||||
let user = context.message.mentions.users.first();
|
||||
|
||||
// If a user was pinged
|
||||
if (user) {
|
||||
// Gets the guild member object of the pinged user
|
||||
let member = context.message.guild.member(user);
|
||||
|
||||
// If the member object exists, i.e if the user is in the server
|
||||
if (member) {
|
||||
// Gets the part of the argument array which holds the reason
|
||||
let reasonArgs = context.arguments;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
// Joins the reason into a string
|
||||
let reason = reasonArgs.join(" ");
|
||||
|
||||
// If the server is available
|
||||
if (context.message.guild.available) {
|
||||
// If the bot client can kick the mentioned member
|
||||
if (member.kickable) {
|
||||
// The embed to go into the bot log
|
||||
let embedLog = new MessageEmbed()
|
||||
.setTitle("Member Kicked")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${user} \`${user.tag}\``, true)
|
||||
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
||||
.addField("Reason", reason || "*none*")
|
||||
.setThumbnail(user.displayAvatarURL);
|
||||
|
||||
// The embed to go into channel the command was sent in
|
||||
let embedPublic = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${user} has been kicked`);
|
||||
|
||||
// Attemtp to kick the user, if successful send the embeds, if unsuccessful notify the chat and log the error
|
||||
member.kick({ reason: reason }).then(() => {
|
||||
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.kick.logchannel).send(embedLog);
|
||||
context.message.channel.send(embedPublic);
|
||||
|
||||
context.message.delete();
|
||||
}).catch(err => {
|
||||
errorEmbed(context, "An error has occurred");
|
||||
console.log(err);
|
||||
});
|
||||
} else { // If the user isn't kickable
|
||||
errorEmbed(context, "I am unable to kick this user");
|
||||
}
|
||||
}
|
||||
} else { // If the member object is invalid
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
} else { // If the user object is invalid
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to post an embed in case of an error
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = kick;
|
98
commands/mute.js
Normal file
98
commands/mute.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Required Components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class mute extends command {
|
||||
constructor() {
|
||||
// Set the command's run method, description, category, and usage
|
||||
super("mute");
|
||||
super.description = "Mutes the mentioned user with an optional reason";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<@user> [reason]";
|
||||
|
||||
// Set the required configs for the command
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredConfigs = "logchannel";
|
||||
super.requiredConfigs = "muterole";
|
||||
}
|
||||
|
||||
// The command's run method
|
||||
mute(context) {
|
||||
// Check if the user has the mod role
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
|
||||
// Get the user first pinged in the message
|
||||
let user = context.message.mentions.users.first();
|
||||
|
||||
// If the user object exists
|
||||
if (user) {
|
||||
// Get the guild member object of the mentioned user
|
||||
let member = context.message.guild.member(user);
|
||||
|
||||
// If the member object exists, i.e. if the user is in the server
|
||||
if (member) {
|
||||
// Get the part of the arguments array which contains the reason
|
||||
let reasonArgs = context.arguments;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
// Join the reason into a string
|
||||
let reason = reasonArgs.join(" ");
|
||||
|
||||
// If the server is available
|
||||
if (context.message.guild.available) {
|
||||
// If the bot client can manage the user's roles
|
||||
if (member.manageable) {
|
||||
// The embed to go into the bot log
|
||||
let embedLog = new MessageEmbed()
|
||||
.setTitle("Member Muted")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${user} \`${user.tag}\``, true)
|
||||
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
||||
.addField("Reason", reason || "*none*")
|
||||
.setThumbnail(user.displayAvatarURL);
|
||||
|
||||
// The embed to go into the channel the command was sent in
|
||||
let embedPublic = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${user} has been muted`)
|
||||
.addField("Reason", reason || "*none*");
|
||||
|
||||
// Get the 'Muted' role
|
||||
let mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.mute.muterole);
|
||||
|
||||
// Attempt to mute the user, if successful send the embeds, if not log the error
|
||||
member.roles.add(mutedRole, reason).then(() => {
|
||||
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.mute.logchannel).send(embedLog);
|
||||
context.message.channel.send(embedPublic);
|
||||
|
||||
context.message.delete();
|
||||
}).catch(err => {
|
||||
errorEmbed(context, "An error occurred");
|
||||
console.log(err);
|
||||
});
|
||||
} else { // If the bot can't manage the user
|
||||
errorEmbed(context, "I am unable to mute this user");
|
||||
}
|
||||
}
|
||||
} else { // If the member object doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
} else { // If the user object doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send an embed when an error occurs
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = mute;
|
98
commands/unmute.js
Normal file
98
commands/unmute.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Required components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class unmute extends command {
|
||||
constructor() {
|
||||
// Set run method, description, category, usage
|
||||
super("unmute");
|
||||
super.description = "Unmutes the mentioned user with an optional reason";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<@user> [reason]";
|
||||
|
||||
// Set required configs
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredConfigs = "logchannel";
|
||||
super.requiredConfigs = "muterole";
|
||||
}
|
||||
|
||||
// The command's run method
|
||||
unmute(context) {
|
||||
// Check if the user has the mod role
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
|
||||
// Get the user first pinged in the message
|
||||
let user = context.message.mentions.users.first();
|
||||
|
||||
// If the user object exists
|
||||
if (user) {
|
||||
// Get the guild member object from the pinged user
|
||||
let member = context.message.guild.member(user);
|
||||
|
||||
// If the member object exists, i.e. if the user is in the server
|
||||
if (member) {
|
||||
// Get the part of the argument array which contains the reason
|
||||
let reasonArgs = context.arguments;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
// Join the array into a string
|
||||
let reason = reasonArgs.join(" ");
|
||||
|
||||
// If the server is available
|
||||
if (context.message.guild.available) {
|
||||
// If the bot client can manage the user
|
||||
if (member.manageable) {
|
||||
// The embed to go into the bot log
|
||||
let embedLog = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setTitle("Member Unmuted")
|
||||
.addField("User", `${user} \`${user.tag}\``, true)
|
||||
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
||||
.addField("Reason", reason || "*none*")
|
||||
.setThumbnail(user.displayAvatarURL);
|
||||
|
||||
// The embed to go into the channel the command was sent in
|
||||
let embedPublic = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${user} has been unmuted`)
|
||||
.addField("Reason", reason || "*none*");
|
||||
|
||||
// Get the muted role
|
||||
let mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.unmute.muterole);
|
||||
|
||||
// Attempt to remove the role from the user, and then send the embeds. If unsuccessful log the error
|
||||
member.roles.remove(mutedRole, reason).then(() => {
|
||||
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.unmute.logchannel).send(embedLog);
|
||||
context.message.channel.send(embedPublic);
|
||||
|
||||
context.message.delete();
|
||||
}).catch(err => {
|
||||
errorEmbed(context, "An error occurred");
|
||||
console.log(err);
|
||||
});
|
||||
} else { // If the bot can't manage the user
|
||||
errorEmbed(context, "I am unable to unmute this user");
|
||||
}
|
||||
}
|
||||
} else { // If the member object doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
} else { // If the user object doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send an embed in case of an error
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = unmute;
|
86
commands/warn.js
Normal file
86
commands/warn.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Required Components
|
||||
const { command } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
const embedColor = "0x3050ba";
|
||||
|
||||
// Command Class
|
||||
class warn extends command {
|
||||
constructor() {
|
||||
// Set the run method, description, category, and usage
|
||||
super("warn");
|
||||
super.description = "Warns the mentioned user with an optional reason";
|
||||
super.category = "Moderation";
|
||||
super.usage = "<@user> [reason]";
|
||||
|
||||
// Set the required configs
|
||||
super.requiredConfigs = "modrole";
|
||||
super.requiredConfigs = "logchannel";
|
||||
}
|
||||
|
||||
// The command's run method
|
||||
warn(context) {
|
||||
// If the user has the mod role
|
||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.warn.modrole)) {
|
||||
// Get the user first pinged in the message
|
||||
let user = context.message.mentions.users.first();
|
||||
|
||||
// If the user object exists
|
||||
if (user) {
|
||||
// Get the guild member object from the user
|
||||
let member = context.message.guild.member(user);
|
||||
|
||||
// If the member object exists. i.e. if the user is in the server
|
||||
if (member) {
|
||||
// Get the part of the argument array which the reason is in
|
||||
let reasonArgs = context.arguments;
|
||||
reasonArgs.splice(0, 1);
|
||||
|
||||
// Join the array into a string
|
||||
let reason = reasonArgs.join(" ");
|
||||
|
||||
// If the server is available
|
||||
if (context.message.guild.available) {
|
||||
// The embed to go into the bot log
|
||||
let embedLog = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setTitle("Member Warned")
|
||||
.addField("User", `${user} \`${user.tag}\``, true)
|
||||
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
||||
.addField("Reason", reason || "*none*")
|
||||
.setThumbnail(user.displayAvatarURL);
|
||||
|
||||
// The embed to go into the channel the command was sent in
|
||||
let embedPublic = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(`${user} has been warned`)
|
||||
.addField("Reason", reason || "*none*");
|
||||
|
||||
// Send the embeds
|
||||
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.warn.logchannel).send(embedLog);
|
||||
context.message.channel.send(embedPublic);
|
||||
|
||||
context.message.delete();
|
||||
}
|
||||
} else { // If the member objest doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
} else { // If the user object doesn't exist
|
||||
errorEmbed(context, "Please specify a valid user");
|
||||
}
|
||||
} else { // If the user isn't mod
|
||||
errorEmbed(context, "You do not have permission to run this command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send an embed in case of an error
|
||||
function errorEmbed(context, message) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(embedColor)
|
||||
.setDescription(message);
|
||||
|
||||
context.message.channel.send(embed);
|
||||
}
|
||||
|
||||
module.exports = warn;
|
115
package-lock.json
generated
Normal file
115
package-lock.json
generated
Normal file
|
@ -0,0 +1,115 @@
|
|||
{
|
||||
"name": "vylbot-app",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@discordjs/collection": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
|
||||
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
|
||||
},
|
||||
"@discordjs/form-data": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
|
||||
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"requires": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"discord.js": {
|
||||
"version": "12.4.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.4.1.tgz",
|
||||
"integrity": "sha512-KxOB8LOAN3GmrvkD6a6Fr1nlfArIFZ+q7Uqg4T/5duB90GZy9a0/Py2E+Y+eHKP6ZUCR2mbNMLCcHGjahiaNqA==",
|
||||
"requires": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prism-media": "^1.2.2",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
}
|
||||
},
|
||||
"event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.44.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
|
||||
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.27",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
|
||||
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
|
||||
"requires": {
|
||||
"mime-db": "1.44.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"prism-media": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.2.tgz",
|
||||
"integrity": "sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw=="
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"vylbot-core": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/vylbot-core/-/vylbot-core-1.0.4.tgz",
|
||||
"integrity": "sha512-KS2+Tl8RiXwhxMj2ja3c3rWXDlY5n7458Z+o29szweoz+UjX9GmCseIcy5iajEv6Snrh4kYe5PE8JJ5jfT2svw==",
|
||||
"requires": {
|
||||
"discord.js": "^12.3.1"
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
|
||||
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
|
||||
}
|
||||
}
|
||||
}
|
22
package.json
Normal file
22
package.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "vylbot-app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "bot.js",
|
||||
"scripts": {
|
||||
"test": "echo \"No tests specified\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Vylpes/vylbot-app.git"
|
||||
},
|
||||
"author": "Vylpes",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Vylpes/vylbot-app/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Vylpes/vylbot-app#readme",
|
||||
"dependencies": {
|
||||
"vylbot-core": "^1.0.4"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue