forked from xrenata/discord-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Commands, Events , Handler, Functions
- Loading branch information
Showing
11 changed files
with
205 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,20 @@ | ||
# discordjs-handler | ||
*You just need to fill in the config.json file. If you do not enter a value in the GuildID section, you will see slash commands on all servers. | ||
# Features | ||
* Logging to the console in table form | ||
* Multi-file event system | ||
* Function handler | ||
* Detailed information in console | ||
* Multi-file command system | ||
* DB support (soon) | ||
# Install | ||
* type ``npm install`` | ||
* fill your config | ||
* start the bot with ``node index.js`` | ||
# Bugs and Errors | ||
* In case of any error, you can contact me via discord. | ||
<div align="center"> | ||
<a href="https://discord.com/users/937316083533230110"><img src="https://lanyard-profile-readme.vercel.app/api/937316083533230110?borderRadius=25px&bg=#282a36"></a> | ||
|
||
|
||
|
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,10 @@ | ||
const { SlashCommandBuilder } = require('@discordjs/builders'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('command') | ||
.setDescription('command info'), | ||
async run(client, interaction) { | ||
//code | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"owner": "937316083533230110", | ||
"client": { | ||
"TOKEN": "", | ||
"ID": "" | ||
}, | ||
"handlers": { | ||
"slash": { | ||
"GuildID": "" | ||
} | ||
} | ||
} |
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,13 @@ | ||
const client = require("../../index.js"); | ||
const config = require("../../config.json"); | ||
const ms = require("ms"); | ||
|
||
client.once('ready', async () => { | ||
console.log(`[CLIENT] ${client.user.tag} login.`); | ||
|
||
const up = ms(ms(Math.round(process.uptime() - (client.uptime / 1000)) + '')); | ||
|
||
console.log(`[NODEJS] Client login time : ${up} `); | ||
|
||
client.user.setActivity(`/help`) | ||
}); |
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,17 @@ | ||
const client = require('../../index.js'); | ||
const config = require("../../config.json"); | ||
|
||
client.on('interactionCreate', async interaction => { | ||
if (!interaction.isCommand()) return; | ||
|
||
const command = client.slash_commands.get(interaction.commandName); | ||
|
||
if (!command) return interaction.reply({ content: "Error No Content-Disposition.", ephemeral: true }); | ||
|
||
try { | ||
await command.run(client, interaction); | ||
} catch (e) { | ||
|
||
await interaction.reply({ content: "Error.", ephemeral: 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,21 @@ | ||
const { readdirSync } = require('fs'); | ||
const ascii = require('ascii-table'); | ||
let table = new ascii("Events Handler:"); | ||
table.setHeading('Events:', 'Status:'); | ||
|
||
module.exports = (client) => { | ||
readdirSync('./events/').forEach(dir => { | ||
const events = readdirSync(`./events/${dir}`).filter(file => file.endsWith('.js')); | ||
for(let file of events) { | ||
let pull = require(`../events/${dir}/${file}`); | ||
if(pull.name) { | ||
client.events.set(pull.name, pull); | ||
} else { | ||
table.addRow(file, '🟩'); | ||
continue; | ||
} | ||
} | ||
}); | ||
console.log(table.toString()); | ||
console.log(`[HANDLER] ./events files uploaded.`); | ||
} |
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,12 @@ | ||
const client = global.client; | ||
const { TextChannel, EmbedBuilder } = require("discord.js"); | ||
module.exports = async client => { | ||
function clean(text) { | ||
if (typeof text !== "string") | ||
text = require("util").inspect(text, { depth: 0 }); | ||
text = text | ||
.replace(/`/g, "`" + String.fromCharCode(8203)) | ||
.replace(/@/g, "@" + String.fromCharCode(8203)); | ||
return text; | ||
} | ||
} |
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,53 @@ | ||
const { REST } = require('@discordjs/rest'); | ||
const { Routes } = require('discord-api-types/v9'); | ||
const fs = require('node:fs'); | ||
const { readdirSync } = require("fs"); | ||
const config = require("../config.json"); | ||
const ascii = require("ascii-table"); | ||
let table = new ascii("Slash Commands Handler"); | ||
table.setHeading('COMMANDS:', 'STATUS:'); | ||
let cmd = []; | ||
|
||
module.exports = (client) => { | ||
readdirSync("./slash_commands/").forEach(dir => { | ||
const commands = readdirSync(`./slash_commands/${dir}`).filter(file => file.endsWith(".js")); | ||
for (let file of commands) { | ||
const command = require(`../slash_commands/${dir}/${file}`); | ||
if (command.data.name) { | ||
cmd.push(command.data.toJSON()); | ||
client.slash_commands.set(command.data.name, command); | ||
table.addRow(client.slash_commands.size, file, '🟩'); | ||
} else { | ||
table.addRow(client.slash_commands.size, file, '🟥'); | ||
continue; | ||
} | ||
} | ||
}); | ||
|
||
const rest = new REST({ version: '9' }).setToken(process.env.TOKEN || config.client.TOKEN); | ||
|
||
(async () => { | ||
try { | ||
if (!config.client.ID) { | ||
console.log("[WARN] The necessary steps for the slash commands to be active have not been completed. Read the readme.md file and fill in the required information.."); | ||
process.exit(1); | ||
} | ||
if(!config.handlers.slash.guildID) { | ||
await rest.put( | ||
Routes.applicationCommands(config.client.ID), | ||
{ body: cmd }, | ||
); | ||
} else { | ||
await rest.put( | ||
Routes.applicationGuildCommands(config.client.ID, config.handlers.slash.guildID), | ||
{ body: cmd }, | ||
); | ||
}; | ||
|
||
console.log(table.toString()); | ||
console.log(`[HANDLER] ${client.slash_commands.size} Slash Commands uploaded.`); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
})(); | ||
} |
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,30 @@ | ||
const { Client, Collection, MessageEmbed } = require("discord.js"); | ||
const { REST } = require('@discordjs/rest'); | ||
const { Routes } = require('discord-api-types/v9'); | ||
const fs = require("node:fs"); | ||
const config = require("./config.json"); | ||
const client = new Client({ | ||
intents: 32767 | ||
}); | ||
|
||
client.config = require("./config") | ||
client.slash_commands = new Collection(); | ||
client.events = new Collection(); | ||
|
||
module.exports = client; | ||
|
||
["slash", "event" , "function"].forEach(handler => { | ||
require(`./handlers/${handler}`)(client); | ||
}); | ||
|
||
process.on('unhandledRejection', err => { | ||
console.log(`[HATA] Unhandled promise rejection: ${err.message}.`); | ||
console.log(err); | ||
}); | ||
|
||
const start = process.env.TOKEN || config.client.TOKEN; | ||
if (!start) { | ||
console.warn("[Warn] Token!").then(async () => process.exit(1)); | ||
} else { | ||
client.login(start).catch(() => console.log("[Warn] Token error.")); | ||
} |
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,7 @@ | ||
{ | ||
"dependencies": { | ||
"ascii-table": "^0.0.9", | ||
"discord.js": "^14.13.0", | ||
"ms": "^2.1.3" | ||
} | ||
} |
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,10 @@ | ||
const { SlashCommandBuilder } = require('@discordjs/builders'); | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('ping') | ||
.setDescription('Botun gecikme süresini verir.'), | ||
async run(client, interaction) { | ||
interaction.reply(`${client.ws.ping}`) | ||
}, | ||
}; |