-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
314 additions
and
98 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,22 @@ | ||
const { Message, PermissionFlagsBits } = require("discord.js"); | ||
const { Bot } = require("../../../handlers/Client"); | ||
|
||
module.exports = { | ||
name: "ping", | ||
description: "Get Bot Real Ping !!", | ||
userPermissions: PermissionFlagsBits.SendMessages, | ||
botPermissions: PermissionFlagsBits.SendMessages, | ||
category: "Misc", | ||
cooldown: 5, | ||
/** | ||
* | ||
* @param {Bot} client | ||
* @param {Message} message | ||
* @param {String[]} args | ||
* @param {String} prefix | ||
*/ | ||
run: async (client, message, args, prefix) => { | ||
// Code | ||
return client.sendEmbed(message, `🏓 Pong \`${client.ws.ping}\``); | ||
}, | ||
}; |
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 { | ||
CommandInteraction, | ||
ApplicationCommandType, | ||
PermissionFlagsBits, | ||
} = require("discord.js"); | ||
const { Bot } = require("../../../handlers/Client"); | ||
|
||
module.exports = { | ||
name: "ping", | ||
description: `Get Bot Real Ping !!`, | ||
userPermissions: PermissionFlagsBits.SendMessages, | ||
botPermissions: PermissionFlagsBits.SendMessages, | ||
category: "Misc", | ||
type: ApplicationCommandType.ChatInput, | ||
/** | ||
* | ||
* @param {Bot} client | ||
* @param {CommandInteraction} interaction | ||
*/ | ||
run: async (client, interaction) => { | ||
// Code | ||
return client.sendEmbed(interaction, `🏓 Pong \`${client.ws.ping}\``); | ||
}, | ||
}; |
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
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
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 |
---|---|---|
@@ -1,65 +1,65 @@ | ||
const { Collection } = require("discord.js"); | ||
const { EmbedBuilder, PermissionsBitField } = require("discord.js"); | ||
const { cooldown } = require("../handlers/functions"); | ||
const client = require("../index"); | ||
const { PREFIX } = require("../settings/config"); | ||
|
||
client.on("messageCreate", async (message) => { | ||
if (message.author.bot || !message.guild) return; | ||
if (message.author.bot || !message.guild || !message.id) return; | ||
|
||
let prefix = PREFIX; | ||
let args = message.content.slice(PREFIX.length).trim().split(/ +/); | ||
let cmd = args.shift()?.toLowerCase(); | ||
const command = client.mcommands.get(cmd); | ||
let mentionprefix = new RegExp( | ||
`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*` | ||
); | ||
if (!mentionprefix.test(message.content)) return; | ||
const [, nprefix] = message.content.match(mentionprefix); | ||
const args = message.content.slice(nprefix.length).trim().split(/ +/); | ||
const cmd = args.shift().toLowerCase(); | ||
if (cmd.length === 0) { | ||
if (nprefix.includes(client.user.id)) { | ||
return message.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setColor(client.config.embed.color) | ||
.setDescription( | ||
` ${client.config.emoji.success} To See My All Commands Type \`/help\` or \`${prefix}help\`` | ||
), | ||
], | ||
}); | ||
} | ||
} | ||
const command = | ||
client.mcommands.get(cmd) || | ||
client.mcommands.find((cmds) => cmds.aliases && cmds.aliases.includes(cmd)); | ||
if (!command) return; | ||
if (command) { | ||
if ( | ||
command.userPermissions && | ||
!message.member.permissions.has(command.userPermissions) | ||
!message.member.permissions.has( | ||
PermissionsBitField.resolve(command.userPermissions) | ||
) | ||
) { | ||
return message.reply({ | ||
content: `you don't have enough permissions !!`, | ||
}); | ||
return client.sendEmbed(message, `You don't have enough Permissions !!`); | ||
} else if ( | ||
command.botPermissions && | ||
!message.guild.members.me.permissions.has(command.botPermissions) | ||
!message.guild.members.me.permissions.has( | ||
PermissionsBitField.resolve(command.botPermissions) | ||
) | ||
) { | ||
return message.reply({ | ||
content: `i don't have enough permissions !!`, | ||
}); | ||
return client.sendEmbed(message, `I don't have enough Permissions !!`); | ||
} else if (cooldown(message, command)) { | ||
return message.reply({ | ||
content: ` You are On Cooldown , wait \`${cooldown( | ||
return client.sendEmbed( | ||
message, | ||
` You are On Cooldown , wait \`${cooldown( | ||
message, | ||
command | ||
).toFixed()}\` Seconds`, | ||
}); | ||
).toFixed()}\` Seconds` | ||
); | ||
} else { | ||
command.run(client, message, args, prefix); | ||
} | ||
} | ||
}); | ||
|
||
function cooldown(message, cmd) { | ||
if (!message || !cmd) return; | ||
let { client, member } = message; | ||
if (!client.cooldowns.has(cmd.name)) { | ||
client.cooldowns.set(cmd.name, new Collection()); | ||
} | ||
const now = Date.now(); | ||
const timestamps = client.cooldowns.get(cmd.name); | ||
const cooldownAmount = cmd.cooldown * 1000; | ||
if (timestamps.has(member.id)) { | ||
const expirationTime = timestamps.get(member.id) + cooldownAmount; | ||
if (now < expirationTime) { | ||
const timeLeft = (expirationTime - now) / 1000; //get the lefttime | ||
//return true | ||
return timeLeft; | ||
} else { | ||
timestamps.set(member.id, now); | ||
setTimeout(() => timestamps.delete(member.id), cooldownAmount); | ||
return false; | ||
} | ||
} else { | ||
timestamps.set(member.id, now); | ||
setTimeout(() => timestamps.delete(member.id), cooldownAmount); | ||
return false; | ||
} | ||
function escapeRegex(newprefix) { | ||
return newprefix.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`); | ||
} |
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,86 @@ | ||
const { | ||
Client, | ||
GatewayIntentBits, | ||
Partials, | ||
Collection, | ||
EmbedBuilder, | ||
} = require("discord.js"); | ||
|
||
class Bot extends Client { | ||
constructor() { | ||
super({ | ||
partials: [ | ||
Partials.Channel, | ||
Partials.GuildMember, | ||
Partials.Message, | ||
Partials.User, | ||
], | ||
intents: [ | ||
GatewayIntentBits.Guilds, | ||
GatewayIntentBits.GuildMessages, | ||
GatewayIntentBits.GuildVoiceStates, | ||
GatewayIntentBits.MessageContent, | ||
GatewayIntentBits.GuildMembers, | ||
], | ||
shards: "auto", | ||
failIfNotExists: false, | ||
allowedMentions: { | ||
parse: ["everyone", "roles", "users"], | ||
users: [], | ||
roles: [], | ||
repliedUser: false, | ||
}, | ||
}); | ||
|
||
// global variables | ||
this.config = require("../settings/config"); | ||
this.scommands = new Collection(); | ||
this.mcommands = new Collection(); | ||
this.cooldowns = new Collection(); | ||
this.events = 0; | ||
} | ||
|
||
async build(token) { | ||
await loadHandlers(this); | ||
this.login(token); | ||
} | ||
|
||
sendEmbed(interaction, data) { | ||
if (interaction.deferred) { | ||
interaction | ||
.followUp({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setColor(this.config.embed.color) | ||
.setDescription(`${data.substring(0, 3000)}`), | ||
], | ||
}) | ||
.catch((e) => {}); | ||
} else { | ||
interaction | ||
.reply({ | ||
embeds: [ | ||
new EmbedBuilder() | ||
.setColor(this.config.embed.color) | ||
.setDescription(`${data.substring(0, 3000)}`), | ||
], | ||
}) | ||
.catch((e) => {}); | ||
} | ||
} | ||
|
||
getFooter(user) { | ||
return { | ||
text: `Requested By ${user.username}`, | ||
iconURL: user.displayAvatarURL(), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = { Bot }; | ||
|
||
function loadHandlers(client) { | ||
["handler"].forEach((file) => { | ||
require(`./${file}`)(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,37 @@ | ||
const { Interaction, Collection } = require("discord.js"); | ||
|
||
/** | ||
* | ||
* @param {Interaction} interaction | ||
* @param {String} cmd | ||
*/ | ||
function cooldown(interaction, cmd) { | ||
if (!interaction || !cmd) return; | ||
let { client, member } = interaction; | ||
if (!client.cooldowns.has(cmd.name)) { | ||
client.cooldowns.set(cmd.name, new Collection()); | ||
} | ||
const now = Date.now(); | ||
const timestamps = client.cooldowns.get(cmd.name); | ||
const cooldownAmount = cmd.cooldown * 1000; | ||
if (timestamps.has(member.id)) { | ||
const expirationTime = timestamps.get(member.id) + cooldownAmount; | ||
if (now < expirationTime) { | ||
const timeLeft = (expirationTime - now) / 1000; //get the lefttime | ||
//return true | ||
return timeLeft; | ||
} else { | ||
timestamps.set(member.id, now); | ||
setTimeout(() => timestamps.delete(member.id), cooldownAmount); | ||
return false; | ||
} | ||
} else { | ||
timestamps.set(member.id, now); | ||
setTimeout(() => timestamps.delete(member.id), cooldownAmount); | ||
return false; | ||
} | ||
} | ||
|
||
module.exports = { | ||
cooldown, | ||
}; |
Oops, something went wrong.