Skip to content
Snippets Groups Projects
Commit 058a9c73 authored by Reviath's avatar Reviath
Browse files

Added welcome-channel command.

parent c86e4083
No related branches found
No related tags found
No related merge requests found
const errors = require('../errors.json');
const config = require('../config.json');
exports.run = async (client, message , args, connection) => {
if(!message.member.hasPermission('ADMINISTRATOR')) {
message.channel.send(errors.insufficient_permission_for_user).catch(e => {
return;
});
};
if (!args[0]) {
message.channel.send(`${errors.insufficient_args}`).catch(e => {
return;
});
return;
};
let channel;
await connection.query(`SELECT channel FROM welcome_channel WHERE guild ='${message.guild.id}'`, function (err, result) {
if (err) {
throw err;
};
if (result.length > 0) {
channel = result[0].channel;
} else {
channel = "none";
};
});
if (args[0] == "reset") {
if (channel == "none"){
message.channel.send(errors.not_existing_on_db).catch(e => {
return;
});
return;
} else {
await connection.query(`DELETE FROM welcome_channel WHERE guild ='${message.guild.id}'`, function (err, result) {
if (err){
throw err;
};
});
message.channel.send('Successful!').catch(e => {
return;
});
};
} else if (!message.mentions.channels.first()) {
message.channel.send(errors.insufficient_args).catch(e => {
return;
});
} else if (message.mentions.channels.first()) {
if (channel == "none") {
connection.query(`INSERT INTO welcome_channel (guild, channel) VALUES ('${message.guild.id}', '${message.mentions.channels.first().id}')`, function (err, result) {
if (err) {
throw err;
};
});
} else {
const prefixdb = await new Promise((resolve, reject) => {
connection.query(`SELECT prefix FROM prefixes WHERE guild ='${message.guild.id}'`, function (err, result) {
if (err)
reject(err);
resolve(result);
});
});
var prefix;
if(prefixdb.length < 1) {
prefix = config.prefix;
} else {
prefix = prefixdb[0].prefix;
};
message.channel.send(`Welcome channel is already existing. To reset type \`${prefix}welcome-channel reset\`.`).catch(e => {
return;
});
};
};
};
module.exports.help = {
name: 'welcome-channel',
aliases: ['welcome_channel', 'welcomechannel']
};
......@@ -5,5 +5,6 @@
"unknown_error": "An error occurred while executing this command.",
"insufficient_args": "You must specify all required args",
"cannot_send_embed": "Cannot send an embed.",
"owner_only": "You don't own this bot."
"owner_only": "You don't own this bot.",
"not_existing_on_db": "It's not existing on database, so you can't reset."
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment