mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-22 15:53:08 +02:00
update
This commit is contained in:
parent
74fd489354
commit
61310e09b6
@ -1,26 +1,31 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
|
const { version } = require('../package.json');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'help',
|
name: 'help',
|
||||||
description: 'Displays help menu',
|
description: 'Displays help menu',
|
||||||
usage: 'help [command]',
|
usage: '[command]',
|
||||||
aliases: ['command', 'commands'],
|
aliases: ['command', 'commands'],
|
||||||
execute(message, args, config, version) {
|
args: false,
|
||||||
const client = message.client;
|
cooldown: 5,
|
||||||
|
execute(message, args, config, version) {
|
||||||
|
const client = message.client;
|
||||||
// command starts here
|
// command starts here
|
||||||
message.delete();
|
message.delete();
|
||||||
if(config.useEmbeds) {
|
if (config.useEmbeds) {
|
||||||
const embed = new Discord.RichEmbed()
|
const embed = new Discord.RichEmbed()
|
||||||
.setAuthor(`${client.user.username} / Commands`, client.user.avatarURL)
|
.setAuthor(`${client.user.username} / Commands`, client.user.avatarURL)
|
||||||
.setColor(config.colour)
|
.setColor(config.colour)
|
||||||
.addField("...", `...`, true)
|
.addField("...", `...`, true)
|
||||||
.addField("...", `...`, true)
|
.addField("...", `...`, true)
|
||||||
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
||||||
message.channel.send({embed})
|
message.channel.send({
|
||||||
|
embed
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``)
|
message.channel.send(`**Prefix =** \`${config.prefix}\`\n**Bot Version =** \`${version}\``)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// command ends here
|
// command ends here
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'new',
|
name: 'new',
|
||||||
description: 'Create a new ticket',
|
description: 'Create a new ticket',
|
||||||
usage: 'new [brief description]',
|
usage: '<brief description>',
|
||||||
|
aliases: ['ticket'],
|
||||||
|
args: true,
|
||||||
execute(message, args, config) {
|
execute(message, args, config) {
|
||||||
// command starts here
|
// command starts here
|
||||||
message.delete();
|
message.delete();
|
||||||
|
134
index.js
134
index.js
@ -45,6 +45,8 @@ const config = require('./config.json');
|
|||||||
const { version, homepage } = require('./package.json');
|
const { version, homepage } = require('./package.json');
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
client.commands = new Discord.Collection();
|
client.commands = new Discord.Collection();
|
||||||
|
const cooldowns = new Discord.Collection();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||||
@ -73,48 +75,59 @@ client.once('ready', () => { // after bot has logged in
|
|||||||
console.log('');
|
console.log('');
|
||||||
console.log(`Starting up...`)
|
console.log(`Starting up...`)
|
||||||
for (const file of commands) {
|
for (const file of commands) {
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`);
|
||||||
client.commands.set(command.name, command);
|
client.commands.set(command.name, command);
|
||||||
console.log(`> Loading '${config.prefix}${command.name}' command`);
|
console.log(`> Loading '${config.prefix}${command.name}' command`);
|
||||||
}
|
}
|
||||||
console.log(leeks.colors.green(`Logged in as ${client.user.tag}`))
|
console.log(leeks.colors.green(`Logged in as ${client.user.tag}`))
|
||||||
client.user.setPresence({ game: { name: config.playing }, status: 'online' })
|
client.user.setPresence({
|
||||||
// .then(console.log)
|
game: {
|
||||||
.catch(console.error);
|
name: config.playing
|
||||||
|
},
|
||||||
|
status: 'online'
|
||||||
|
})
|
||||||
|
// .then(console.log)
|
||||||
|
.catch(console.error);
|
||||||
// console.log(leeks.colors.green(`Set playing status as `) + leeks.colors.yellow(`'${config.playing}${config.prefix}help'`));
|
// console.log(leeks.colors.green(`Set playing status as `) + leeks.colors.yellow(`'${config.playing}${config.prefix}help'`));
|
||||||
|
|
||||||
if(config.useEmbeds) {
|
if (config.useEmbeds) {
|
||||||
const embed = new Discord.RichEmbed()
|
const embed = new Discord.RichEmbed()
|
||||||
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
||||||
.setColor("#2ECC71")
|
.setColor("#2ECC71")
|
||||||
.setDescription(":white_check_mark: **Started succesfully**")
|
.setDescription(":white_check_mark: **Started succesfully**")
|
||||||
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
||||||
client.channels.get(config.logChannel).send({embed})
|
client.channels.get(config.logChannel).send({
|
||||||
|
embed
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
||||||
}
|
}
|
||||||
if(client.guilds.get(config.guildID).member(client.user).hasPermission("ADMINISTRATOR", false)){
|
if (client.guilds.get(config.guildID).member(client.user).hasPermission("ADMINISTRATOR", false)) {
|
||||||
console.log(leeks.colors.green(`Required permissions have been granted`))
|
console.log(leeks.colors.green(`Required permissions have been granted`))
|
||||||
if(config.useEmbeds) {
|
if (config.useEmbeds) {
|
||||||
const embed = new Discord.RichEmbed()
|
const embed = new Discord.RichEmbed()
|
||||||
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
||||||
.setColor("#2ECC71")
|
.setColor("#2ECC71")
|
||||||
.setDescription(":white_check_mark: **Required permissions have been granted**")
|
.setDescription(":white_check_mark: **Required permissions have been granted**")
|
||||||
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
||||||
client.channels.get(config.logChannel).send({embed})
|
client.channels.get(config.logChannel).send({
|
||||||
|
embed
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(leeks.colors.red(`Required permissions have not been granted`))
|
console.log(leeks.colors.red(`Required permissions have not been granted`))
|
||||||
console.log(leeks.colors.red(`Please give the bot the 'ADMINISTRATOR' permission`))
|
console.log(leeks.colors.red(`Please give the bot the 'ADMINISTRATOR' permission`))
|
||||||
if(config.useEmbeds) {
|
if (config.useEmbeds) {
|
||||||
const embed = new Discord.RichEmbed()
|
const embed = new Discord.RichEmbed()
|
||||||
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
||||||
.setColor("#E74C3C")
|
.setColor("#E74C3C")
|
||||||
.setDescription(":x: **Required permissions have not been granted**\nPlease give the bot the `ADMINISTRATOR` permission")
|
.setDescription(":x: **Required permissions have not been granted**\nPlease give the bot the `ADMINISTRATOR` permission")
|
||||||
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
||||||
client.channels.get(config.logChannel).send({embed})
|
client.channels.get(config.logChannel).send({
|
||||||
|
embed
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
client.channels.get(config.logChannel).send(":white_check_mark: **Started succesfully**")
|
||||||
}
|
}
|
||||||
@ -123,44 +136,81 @@ client.once('ready', () => { // after bot has logged in
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
// if (!message.content.startsWith(config.prefix) || message.author.bot) return;
|
// if (!message.content.startsWith(config.prefix) || message.author.bot) return;
|
||||||
if(message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if (message.channel.type === "dm") {
|
if (message.channel.type === "dm") {
|
||||||
if (message.author.id === client.user.id) return;
|
if (message.author.id === client.user.id) return;
|
||||||
if(config.logDMs){
|
message.channel.send(`Sorry, commands can only be used on the server.`)
|
||||||
if(config.useEmbeds) {
|
if (config.logDMs) {
|
||||||
const embed = new Discord.RichEmbed()
|
if (config.useEmbeds) {
|
||||||
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
const embed = new Discord.RichEmbed()
|
||||||
.setTitle("DM Logger")
|
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
|
||||||
.addField("Username", message.author.tag, true)
|
.setTitle("DM Logger")
|
||||||
.addField("Message", message.content, true)
|
.addField("Username", message.author.tag, true)
|
||||||
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
.addField("Message", message.content, true)
|
||||||
client.channels.get(config.logChannel).send({embed})
|
.setFooter(`${client.guilds.get(config.guildID).name} : DiscordTickets by Eartharoid`);
|
||||||
} else {
|
client.channels.get(config.logChannel).send({
|
||||||
client.channels.get(config.logChannel).send(`DM received from **${message.author.tag} (${message.author.id})** : \n\n\`\`\`${message.content}\`\`\``);
|
embed
|
||||||
}
|
})
|
||||||
} else { return };
|
} else {
|
||||||
|
client.channels.get(config.logChannel).send(`DM received from **${message.author.tag} (${message.author.id})** : \n\n\`\`\`${message.content}\`\`\``);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
if (message.channel.bot) return;
|
if (message.channel.bot) return;
|
||||||
|
|
||||||
// const args = message.content.slice(config.prefix.length).split(/ +/);
|
// const args = message.content.slice(config.prefix.length).split(/ +/);
|
||||||
|
|
||||||
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`);
|
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`);
|
||||||
if (!prefixRegex.test(message.content)) return;
|
if (!prefixRegex.test(message.content)) return;
|
||||||
|
|
||||||
|
const [, matchedPrefix] = message.content.match(prefixRegex);
|
||||||
|
const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
|
||||||
|
const commandName = args.shift().toLowerCase();
|
||||||
|
if (!client.commands.has(commandName)) return;
|
||||||
|
const command = client.commands.get(commandName);
|
||||||
|
|
||||||
|
if (command.args && !args.length) {
|
||||||
|
let reply = `:x: **Arguments were expected but none were provided.**`;
|
||||||
|
|
||||||
|
if (command.usage) {
|
||||||
|
reply += `\n**Usage:** \`${config.prefix}${command.name} ${command.usage}\``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return message.channel.send(reply);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (!cooldowns.has(command.name)) {
|
||||||
|
cooldowns.set(command.name, new Discord.Collection());
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
const timestamps = cooldowns.get(command.name);
|
||||||
|
const cooldownAmount = (command.cooldown || 3) * 1000;
|
||||||
|
|
||||||
|
if (timestamps.has(message.author.id)) {
|
||||||
|
const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
|
||||||
|
|
||||||
|
if (now < expirationTime) {
|
||||||
|
const timeLeft = (expirationTime - now) / 1000;
|
||||||
|
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const [, matchedPrefix] = message.content.match(prefixRegex);
|
|
||||||
const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
|
|
||||||
const command = args.shift().toLowerCase();
|
|
||||||
if (!client.commands.has(command)) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.commands.get(command).execute(message, args, config, version);
|
// client.commands.get(command).execute(message, args, config);
|
||||||
} catch (error) {
|
command.execute(message, args, config);
|
||||||
console.error(error);
|
} catch (error) {
|
||||||
message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`);
|
console.error(error);
|
||||||
console.log(leeks.colors.red(`[ERROR] An unknown error occured whilst executing '${command}' command`));
|
message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`);
|
||||||
}
|
console.log(leeks.colors.red(`[ERROR] An unknown error occured whilst executing '${command}' command`));
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user