Skip to content

Commit 0c37f49

Browse files
authored
✅ Fixed Issue and Updated ✅
✅ Fixed Issue and Updated ✅
1 parent ff96f4e commit 0c37f49

File tree

9 files changed

+314
-98
lines changed

9 files changed

+314
-98
lines changed

Commands/Message/Misc/ping.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { Message, PermissionFlagsBits } = require("discord.js");
2+
const { Bot } = require("../../../handlers/Client");
3+
4+
module.exports = {
5+
name: "ping",
6+
description: "Get Bot Real Ping !!",
7+
userPermissions: PermissionFlagsBits.SendMessages,
8+
botPermissions: PermissionFlagsBits.SendMessages,
9+
category: "Misc",
10+
cooldown: 5,
11+
/**
12+
*
13+
* @param {Bot} client
14+
* @param {Message} message
15+
* @param {String[]} args
16+
* @param {String} prefix
17+
*/
18+
run: async (client, message, args, prefix) => {
19+
// Code
20+
return client.sendEmbed(message, `🏓 Pong \`${client.ws.ping}\``);
21+
},
22+
};

Commands/Slash/Misc/ping.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const {
2+
CommandInteraction,
3+
ApplicationCommandType,
4+
PermissionFlagsBits,
5+
} = require("discord.js");
6+
const { Bot } = require("../../../handlers/Client");
7+
8+
module.exports = {
9+
name: "ping",
10+
description: `Get Bot Real Ping !!`,
11+
userPermissions: PermissionFlagsBits.SendMessages,
12+
botPermissions: PermissionFlagsBits.SendMessages,
13+
category: "Misc",
14+
type: ApplicationCommandType.ChatInput,
15+
/**
16+
*
17+
* @param {Bot} client
18+
* @param {CommandInteraction} interaction
19+
*/
20+
run: async (client, interaction) => {
21+
// Code
22+
return client.sendEmbed(interaction, `🏓 Pong \`${client.ws.ping}\``);
23+
},
24+
};

command_example.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const {
33
CommandInteraction,
44
ApplicationCommandType,
55
PermissionFlagsBits,
6-
Client,
76
} = require("discord.js");
7+
const { Bot } = require("../../../handlers/Client");
88

99
module.exports = {
1010
name: "",
@@ -15,7 +15,7 @@ module.exports = {
1515
type: ApplicationCommandType.ChatInput,
1616
/**
1717
*
18-
* @param {Client} client
18+
* @param {Bot} client
1919
* @param {CommandInteraction} interaction
2020
*/
2121
run: async (client, interaction) => {
@@ -67,18 +67,20 @@ module.exports = {
6767
};
6868

6969
// message commands
70-
const { Message, PermissionFlagsBits, Client } = require("discord.js");
70+
const { Message, PermissionFlagsBits } = require("discord.js");
71+
const { Bot } = require("../../../handlers/Client");
7172

7273
module.exports = {
7374
name: "",
75+
aliases: [],
7476
description: ``,
7577
userPermissions: PermissionFlagsBits.SendMessages,
7678
botPermissions: PermissionFlagsBits.SendMessages,
7779
category: "",
7880
cooldown: 10,
7981
/**
8082
*
81-
* @param {Client} client
83+
* @param {Bot} client
8284
* @param {Message} message
8385
* @param {String[]} args
8486
* @param {String} prefix

events/interactionCreate.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const { InteractionType } = require("discord.js");
1+
const { InteractionType, PermissionsBitField } = require("discord.js");
22
const client = require("../index");
33

44
client.on("interactionCreate", async (interaction) => {
55
// code
6+
if (interaction.user.bot || !interaction.guild) return;
67
if (interaction.type == InteractionType.ApplicationCommand) {
78
const command = client.scommands.get(interaction.commandName);
89
if (!command) {
@@ -13,20 +14,24 @@ client.on("interactionCreate", async (interaction) => {
1314
} else {
1415
if (
1516
command.userPermissions &&
16-
!interaction.member.permissions.has(command.userPermissions)
17+
!interaction.member.permissions.has(
18+
PermissionsBitField.resolve(command.userPermissions)
19+
)
1720
) {
18-
return interaction.reply({
19-
content: `you don't have enough permissions !!`,
20-
ephemeral: true,
21-
});
21+
return client.sendEmbed(
22+
interaction,
23+
`You don't have enough Permissions !!`
24+
);
2225
} else if (
2326
command.botPermissions &&
24-
!interaction.guild.members.me.permissions.has(command.botPermissions)
27+
!interaction.guild.members.me.permissions.has(
28+
PermissionsBitField.resolve(command.botPermissions)
29+
)
2530
) {
26-
return interaction.reply({
27-
content: `i don't have enough permissions !!`,
28-
ephemeral: true,
29-
});
31+
return client.sendEmbed(
32+
interaction,
33+
`I don't have enough Permissions !!`
34+
);
3035
} else {
3136
command.run(client, interaction);
3237
}

events/messageCreate.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
const { Collection } = require("discord.js");
1+
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
2+
const { cooldown } = require("../handlers/functions");
23
const client = require("../index");
34
const { PREFIX } = require("../settings/config");
45

56
client.on("messageCreate", async (message) => {
6-
if (message.author.bot || !message.guild) return;
7+
if (message.author.bot || !message.guild || !message.id) return;
8+
79
let prefix = PREFIX;
8-
let args = message.content.slice(PREFIX.length).trim().split(/ +/);
9-
let cmd = args.shift()?.toLowerCase();
10-
const command = client.mcommands.get(cmd);
10+
let mentionprefix = new RegExp(
11+
`^(<@!?${client.user.id}>|${escapeRegex(prefix)})\\s*`
12+
);
13+
if (!mentionprefix.test(message.content)) return;
14+
const [, nprefix] = message.content.match(mentionprefix);
15+
const args = message.content.slice(nprefix.length).trim().split(/ +/);
16+
const cmd = args.shift().toLowerCase();
17+
if (cmd.length === 0) {
18+
if (nprefix.includes(client.user.id)) {
19+
return message.reply({
20+
embeds: [
21+
new EmbedBuilder()
22+
.setColor(client.config.embed.color)
23+
.setDescription(
24+
` ${client.config.emoji.success} To See My All Commands Type \`/help\` or \`${prefix}help\``
25+
),
26+
],
27+
});
28+
}
29+
}
30+
const command =
31+
client.mcommands.get(cmd) ||
32+
client.mcommands.find((cmds) => cmds.aliases && cmds.aliases.includes(cmd));
1133
if (!command) return;
1234
if (command) {
1335
if (
1436
command.userPermissions &&
15-
!message.member.permissions.has(command.userPermissions)
37+
!message.member.permissions.has(
38+
PermissionsBitField.resolve(command.userPermissions)
39+
)
1640
) {
17-
return message.reply({
18-
content: `you don't have enough permissions !!`,
19-
});
41+
return client.sendEmbed(message, `You don't have enough Permissions !!`);
2042
} else if (
2143
command.botPermissions &&
22-
!message.guild.members.me.permissions.has(command.botPermissions)
44+
!message.guild.members.me.permissions.has(
45+
PermissionsBitField.resolve(command.botPermissions)
46+
)
2347
) {
24-
return message.reply({
25-
content: `i don't have enough permissions !!`,
26-
});
48+
return client.sendEmbed(message, `I don't have enough Permissions !!`);
2749
} else if (cooldown(message, command)) {
28-
return message.reply({
29-
content: ` You are On Cooldown , wait \`${cooldown(
50+
return client.sendEmbed(
51+
message,
52+
` You are On Cooldown , wait \`${cooldown(
3053
message,
3154
command
32-
).toFixed()}\` Seconds`,
33-
});
55+
).toFixed()}\` Seconds`
56+
);
3457
} else {
3558
command.run(client, message, args, prefix);
3659
}
3760
}
3861
});
3962

40-
function cooldown(message, cmd) {
41-
if (!message || !cmd) return;
42-
let { client, member } = message;
43-
if (!client.cooldowns.has(cmd.name)) {
44-
client.cooldowns.set(cmd.name, new Collection());
45-
}
46-
const now = Date.now();
47-
const timestamps = client.cooldowns.get(cmd.name);
48-
const cooldownAmount = cmd.cooldown * 1000;
49-
if (timestamps.has(member.id)) {
50-
const expirationTime = timestamps.get(member.id) + cooldownAmount;
51-
if (now < expirationTime) {
52-
const timeLeft = (expirationTime - now) / 1000; //get the lefttime
53-
//return true
54-
return timeLeft;
55-
} else {
56-
timestamps.set(member.id, now);
57-
setTimeout(() => timestamps.delete(member.id), cooldownAmount);
58-
return false;
59-
}
60-
} else {
61-
timestamps.set(member.id, now);
62-
setTimeout(() => timestamps.delete(member.id), cooldownAmount);
63-
return false;
64-
}
63+
function escapeRegex(newprefix) {
64+
return newprefix.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`);
6565
}

handlers/Client.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const {
2+
Client,
3+
GatewayIntentBits,
4+
Partials,
5+
Collection,
6+
EmbedBuilder,
7+
} = require("discord.js");
8+
9+
class Bot extends Client {
10+
constructor() {
11+
super({
12+
partials: [
13+
Partials.Channel,
14+
Partials.GuildMember,
15+
Partials.Message,
16+
Partials.User,
17+
],
18+
intents: [
19+
GatewayIntentBits.Guilds,
20+
GatewayIntentBits.GuildMessages,
21+
GatewayIntentBits.GuildVoiceStates,
22+
GatewayIntentBits.MessageContent,
23+
GatewayIntentBits.GuildMembers,
24+
],
25+
shards: "auto",
26+
failIfNotExists: false,
27+
allowedMentions: {
28+
parse: ["everyone", "roles", "users"],
29+
users: [],
30+
roles: [],
31+
repliedUser: false,
32+
},
33+
});
34+
35+
// global variables
36+
this.config = require("../settings/config");
37+
this.scommands = new Collection();
38+
this.mcommands = new Collection();
39+
this.cooldowns = new Collection();
40+
this.events = 0;
41+
}
42+
43+
async build(token) {
44+
await loadHandlers(this);
45+
this.login(token);
46+
}
47+
48+
sendEmbed(interaction, data) {
49+
if (interaction.deferred) {
50+
interaction
51+
.followUp({
52+
embeds: [
53+
new EmbedBuilder()
54+
.setColor(this.config.embed.color)
55+
.setDescription(`${data.substring(0, 3000)}`),
56+
],
57+
})
58+
.catch((e) => {});
59+
} else {
60+
interaction
61+
.reply({
62+
embeds: [
63+
new EmbedBuilder()
64+
.setColor(this.config.embed.color)
65+
.setDescription(`${data.substring(0, 3000)}`),
66+
],
67+
})
68+
.catch((e) => {});
69+
}
70+
}
71+
72+
getFooter(user) {
73+
return {
74+
text: `Requested By ${user.username}`,
75+
iconURL: user.displayAvatarURL(),
76+
};
77+
}
78+
}
79+
80+
module.exports = { Bot };
81+
82+
function loadHandlers(client) {
83+
["handler"].forEach((file) => {
84+
require(`./${file}`)(client);
85+
});
86+
}

handlers/functions.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { Interaction, Collection } = require("discord.js");
2+
3+
/**
4+
*
5+
* @param {Interaction} interaction
6+
* @param {String} cmd
7+
*/
8+
function cooldown(interaction, cmd) {
9+
if (!interaction || !cmd) return;
10+
let { client, member } = interaction;
11+
if (!client.cooldowns.has(cmd.name)) {
12+
client.cooldowns.set(cmd.name, new Collection());
13+
}
14+
const now = Date.now();
15+
const timestamps = client.cooldowns.get(cmd.name);
16+
const cooldownAmount = cmd.cooldown * 1000;
17+
if (timestamps.has(member.id)) {
18+
const expirationTime = timestamps.get(member.id) + cooldownAmount;
19+
if (now < expirationTime) {
20+
const timeLeft = (expirationTime - now) / 1000; //get the lefttime
21+
//return true
22+
return timeLeft;
23+
} else {
24+
timestamps.set(member.id, now);
25+
setTimeout(() => timestamps.delete(member.id), cooldownAmount);
26+
return false;
27+
}
28+
} else {
29+
timestamps.set(member.id, now);
30+
setTimeout(() => timestamps.delete(member.id), cooldownAmount);
31+
return false;
32+
}
33+
}
34+
35+
module.exports = {
36+
cooldown,
37+
};

0 commit comments

Comments
 (0)