-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from aurora-0025/main
Project Initiated
- Loading branch information
Showing
14 changed files
with
459 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { | ||
Client, | ||
Message, | ||
MessageEmbed, | ||
MessageActionRow, | ||
MessageSelectMenu, | ||
} = require ("discord.js") | ||
const config = require("../../Data/config.json"); | ||
|
||
module.exports = { | ||
name: "command_name", | ||
description: "command_description", | ||
usage: `command_usage`, | ||
aliases: ['command_aliases'], | ||
/** | ||
* | ||
* @param {Client} client | ||
* @param {Message} message | ||
* @param {String[]} args | ||
*/ | ||
run: async (client, message, args) => { | ||
|
||
//CODE THE COMMAND HERE | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const { | ||
Client, | ||
Message, | ||
MessageEmbed, | ||
MessageActionRow, | ||
MessageSelectMenu, | ||
} = require("discord.js"); | ||
const config = require("../../Data/config.json"); | ||
|
||
module.exports = { | ||
name: "help", | ||
description: "Help command for the bot", | ||
usage: `${config.prefix}help`, | ||
aliases: ["help"], | ||
/** | ||
* | ||
* @param {Client} client | ||
* @param {Message} message | ||
* @param {String[]} args | ||
*/ | ||
run: async (client, message, args) => { | ||
message.delete(); | ||
//set the emoji for the categories | ||
const emojis = { | ||
info: "📉", | ||
}; | ||
|
||
const directories = [ | ||
...new Set(client.commands.map((cmd) => cmd.directory)), | ||
]; | ||
|
||
const formatSring = (str) => | ||
`${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`; | ||
|
||
const categories = directories.map((dir) => { | ||
const getCommands = client.commands | ||
.filter((cmd) => cmd.directory === dir) | ||
.map((cmd) => { | ||
return { | ||
name: cmd.name || "there is no name", | ||
description: cmd.description || "there is no description", | ||
usage: cmd.usage || "there is no usage given", | ||
}; | ||
}); | ||
|
||
return { | ||
directory: formatSring(dir), | ||
commands: getCommands, | ||
}; | ||
}); | ||
|
||
const embed = new MessageEmbed() | ||
.setAuthor("choose the category you require help down below") | ||
.setColor(config.accentColor) | ||
.setFooter( | ||
`requested by ${message.author.tag}`, | ||
message.author.avatarURL({ dynamic: true }) | ||
); | ||
|
||
const components = (state) => [ | ||
new MessageActionRow().addComponents( | ||
new MessageSelectMenu() | ||
.setCustomId("help-menu") | ||
.setPlaceholder("SELECT A CATEGORY") | ||
.setDisabled(state) | ||
.addOptions( | ||
categories.map((cmd) => { | ||
return { | ||
label: cmd.directory, | ||
value: cmd.directory.toLowerCase(), | ||
description: `Commands from ${cmd.directory} category`, | ||
emoji: emojis[cmd.directory.toLowerCase() || null], | ||
}; | ||
}) | ||
) | ||
), | ||
]; | ||
|
||
const initialMessage = await message.channel.send({ | ||
embeds: [embed], | ||
components: components(false), | ||
}); | ||
|
||
const filter = (interaction) => interaction.user.id === message.author.id; | ||
|
||
const collector = message.channel.createMessageComponentCollector({ | ||
filter, | ||
componentType: "SELECT_MENU", | ||
}); | ||
|
||
collector.on("collect", (interaction) => { | ||
const [directory] = interaction.values; | ||
const category = categories.find( | ||
(x) => x.directory.toLocaleLowerCase() === directory | ||
); | ||
const categoryEmbed = new MessageEmbed() | ||
.setTitle(`${directory} Commands`) | ||
.setDescription(`Here are the list of commands`) | ||
.addFields( | ||
category.commands.map((cmd) => { | ||
return { | ||
name: `\`${config.prefix}${cmd.name}\``, | ||
value: | ||
`${cmd.description} \n` + "```" + `usage: ${cmd.usage}` + "```", | ||
inline: true, | ||
}; | ||
}) | ||
) | ||
.setColor(config.accentColor); | ||
interaction.update({ embeds: [categoryEmbed] }); | ||
}); | ||
|
||
collector.on("end", () => { | ||
initialMessage.edit({ components: components(true) }); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { Message, Client, MessageEmbed } = require("discord.js"); | ||
const config = require("../../Data/config.json"); | ||
|
||
module.exports = { | ||
name: "ping", | ||
description: "returns websocket ping", | ||
usage: `${config.prefix}ping`, | ||
aliases: ["ping"], | ||
/** | ||
* | ||
* @param {Client} client | ||
* @param {Message} message | ||
* @param {String[]} args | ||
*/ | ||
run: async (client, message, args) => { | ||
message.delete(); | ||
pingEmbed = new MessageEmbed() | ||
.setTitle(`${client.ws.ping} ws ping`) | ||
.setColor(config.accentColor) | ||
.setFooter("© codevisor"); | ||
|
||
message.channel.send({ embeds: [pingEmbed] }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"token": "", | ||
"prefix": ";", | ||
"accentColor": "#21F8F6", | ||
"errorColor": "RED" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { Client, CommandInteraction } = require("discord.js"); | ||
|
||
module.exports = { | ||
name: "ping", | ||
description: "returns websocket ping", | ||
type: "CHAT_INPUT", | ||
/** | ||
* | ||
* @param {Client} client | ||
* @param {CommandInteraction} interaction | ||
* @param {String[]} args | ||
*/ | ||
run: async (client, interaction, args) => { | ||
interaction.followUp({ content: `${client.ws.ping}ms!` }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const Discord = require("discord.js"); | ||
|
||
const Command = require("./Command.js"); | ||
|
||
const Event = require("./Event.js"); | ||
|
||
const config = require("../Data/config.json"); | ||
|
||
const intents = new Discord.Intents(32767); | ||
|
||
const fs = require("fs"); | ||
|
||
class Client extends Discord.Client { | ||
constructor() { | ||
super({ intents }); | ||
|
||
/** | ||
* @type {Discord.Collection<string, Command>} | ||
*/ | ||
this.commands = new Discord.Collection(); | ||
|
||
this.prefix = config.prefix; | ||
} | ||
|
||
start(token) { | ||
fs.readdirSync("./Commands") | ||
.filter((file) => file.endsWith(".js")) | ||
.forEach((file) => { | ||
/** | ||
* @type {Command} | ||
*/ | ||
const command = require(`../Commands/${file}`); | ||
console.log(`Command ${command.name} loaded`); | ||
this.commands.set(command.name, command); | ||
}); | ||
|
||
fs.readdirSync("./Events") | ||
.filter((file) => file.endsWith(".js")) | ||
.forEach((file) => { | ||
/** | ||
* @type {Event} | ||
*/ | ||
const event = require(`../Events/${file}`); | ||
console.log(`Event ${event.event} loaded`); | ||
this.on(event.event, event.run.bind(null, this)); | ||
}); | ||
|
||
this.login(token); | ||
} | ||
} | ||
|
||
module.exports = Client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Client = require("./Client.js"); | ||
|
||
const Discord = require("discord.js"); | ||
|
||
/** | ||
* @param {Discord.Message | Discord.Interaction} message | ||
* @param {string[]} args | ||
* @param {Client} client | ||
*/ | ||
function RunFunction(message, args, client) {} | ||
|
||
class Command { | ||
/** | ||
* @typedef {{name: string, description: string, permission: Discord.PermissionString, run: RunFunction}} CommandOptions | ||
* @param {CommandOptions} options | ||
*/ | ||
constructor(options) { | ||
this.name = options.name; | ||
this.description = options.description; | ||
this.permission = options.permission; | ||
this.run = options.run; | ||
} | ||
} | ||
|
||
module.exports = Command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const Discord = require("discord.js"); | ||
|
||
const Client = require("./Client.js"); | ||
|
||
/** | ||
* @template {keyof Discord.ClientEvents} K | ||
* @param {Client} client | ||
* @param {Discord.ClientEvents[K]} eventArgs | ||
*/ | ||
function RunFunction(client, ...eventArgs) {} | ||
|
||
/** | ||
* @template {keyof Discord.ClientEvents} K | ||
*/ | ||
class Event { | ||
/** | ||
* @param {K} event | ||
* @param {RunFunction<K>} runFunction | ||
*/ | ||
constructor(event, runFunction) { | ||
this.event = event; | ||
this.run = runFunction; | ||
} | ||
} | ||
|
||
module.exports = Event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const client = require("../index"); | ||
|
||
const { | ||
Client, | ||
Message, | ||
MessageEmbed, | ||
MessageButton, | ||
MessageActionRow, | ||
} = require("discord.js"); | ||
|
||
client.on("interactionCreate", async (interaction) => { | ||
// Slash Command Handling | ||
if (interaction.isCommand()) { | ||
await interaction.deferReply({ ephemeral: false }).catch(() => {}); | ||
|
||
const cmd = client.slashCommands.get(interaction.commandName); | ||
if (!cmd) return interaction.followUp({ content: "An error has occured " }); | ||
|
||
const args = []; | ||
|
||
for (let option of interaction.options.data) { | ||
if (option.type === "SUB_COMMAND") { | ||
if (option.name) args.push(option.name); | ||
option.options?.forEach((x) => { | ||
if (x.value) args.push(x.value); | ||
}); | ||
} else if (option.value) args.push(option.value); | ||
} | ||
interaction.member = interaction.guild.members.cache.get( | ||
interaction.user.id | ||
); | ||
|
||
cmd.run(client, interaction, args); | ||
} | ||
|
||
// Context Menu Handling | ||
if (interaction.isContextMenu()) { | ||
await interaction.deferReply({ ephemeral: false }); | ||
const command = client.slashCommands.get(interaction.commandName); | ||
if (command) command.run(client, interaction); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const client = require("../index"); | ||
const { Permissions, MessageEmbed } = require("discord.js"); | ||
client.on("messageCreate", async (message) => { | ||
if ( | ||
message.author.bot || | ||
!message.guild || | ||
!message.content.toLowerCase().startsWith(client.config.prefix) | ||
) | ||
return; | ||
|
||
const [cmd, ...args] = message.content | ||
.slice(client.config.prefix.length) | ||
.trim() | ||
.split(" "); | ||
|
||
const command = | ||
client.commands.get(cmd.toLowerCase()) || | ||
client.commands.find((c) => c.aliases?.includes(cmd.toLowerCase())); | ||
if (command) { | ||
if (!message.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) { | ||
errEmbed = new MessageEmbed() | ||
.setDescription( | ||
"⚠️ **I dont have permission to manage messages** \n please give MANAGE_MESSAGES permission to me" | ||
) | ||
.setColor(config.errorColor) | ||
.setFooter( | ||
`© CodeVisor |this message will be deleted in 5 seconds` | ||
); | ||
return message.channel | ||
.send({ embeds: [errEmbed] }) | ||
.then((msg) => setTimeout(() => msg.delete(), 5000)); | ||
} | ||
} | ||
if (!command) return; | ||
|
||
await command.run(client, message, args); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const client = require("../index"); | ||
|
||
client.on("ready", () => | ||
console.log(`${client.user.tag} is up and ready to go!`) | ||
); |
Oops, something went wrong.