Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/commands/changePrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { setGuildOption } from "../functions";
import { Command } from "../types";

const command: Command = {
name: "changePrefix",
execute: (message, args) => {
let prefix = args[1]
if (!prefix) return message.channel.send("No prefix provided")
if (!message.guild) return;
setGuildOption(message.guild, "prefix", prefix)
message.channel.send("Prefix successfully changed!")
},
permissions: ["Administrator"],
aliases: []
}
enable: true,
name: "changePrefix",
execute: (message, args) => {
let prefix = args[1];
if (!prefix) return message.channel.send("No prefix provided");
if (!message.guild) return;
setGuildOption(message.guild, "prefix", prefix);
message.channel.send("Prefix successfully changed!");
},
permissions: ["Administrator"],
aliases: [],
};

export default command
export default command;
27 changes: 16 additions & 11 deletions src/commands/greet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { PermissionFlagsBits } from "discord.js";
import { Command } from "../types";

const command : Command = {
name: "greet",
execute: (message, args) => {
let toGreet = message.mentions.members?.first()
message.channel.send(`Hello there ${toGreet ? toGreet.user.username : message.member?.user.username}!`)
},
cooldown: 10,
aliases: ["sayhello"],
permissions: ["Administrator", PermissionFlagsBits.ManageEmojisAndStickers] // to test
}
const command: Command = {
enable: true,
name: "greet",
execute: (message, args) => {
let toGreet = message.mentions.members?.first();
message.channel.send(
`Hello there ${
toGreet ? toGreet.user.username : message.member?.user.username
}!`
);
},
cooldown: 10,
aliases: ["sayhello"],
permissions: ["Administrator", PermissionFlagsBits.ManageEmojisAndStickers], // to test
};

export default command
export default command;
23 changes: 12 additions & 11 deletions src/events/guildCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import GuildModel from "../schemas/Guild";
import { BotEvent } from "../types";

const event: BotEvent = {
name: "guildCreate",
execute: (guild : Guild) => {
let newGuild = new GuildModel({
guildID: guild.id,
options: {},
joinedAt: Date.now()
})
newGuild.save()
}
}
enable: true,
name: "guildCreate",
execute: (guild: Guild) => {
let newGuild = new GuildModel({
guildID: guild.id,
options: {},
joinedAt: Date.now(),
});
newGuild.save();
},
};

export default event;
export default event;
91 changes: 56 additions & 35 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
import { Interaction } from "discord.js";
import { BotEvent } from "../types";

const event : BotEvent = {
name: "interactionCreate",
execute: (interaction: Interaction) => {
if (interaction.isChatInputCommand()) {
let command = interaction.client.slashCommands.get(interaction.commandName)
let cooldown = interaction.client.cooldowns.get(`${interaction.commandName}-${interaction.user.username}`)
if (!command) return;
if (command.cooldown && cooldown) {
if (Date.now() < cooldown) {
interaction.reply(`You have to wait ${Math.floor(Math.abs(Date.now() - cooldown) / 1000)} second(s) to use this command again.`)
setTimeout(() => interaction.deleteReply(), 5000)
return
}
interaction.client.cooldowns.set(`${interaction.commandName}-${interaction.user.username}`, Date.now() + command.cooldown * 1000)
setTimeout(() => {
interaction.client.cooldowns.delete(`${interaction.commandName}-${interaction.user.username}`)
}, command.cooldown * 1000)
} else if (command.cooldown && !cooldown) {
interaction.client.cooldowns.set(`${interaction.commandName}-${interaction.user.username}`, Date.now() + command.cooldown * 1000)
}
command.execute(interaction)
} else if (interaction.isAutocomplete()) {
const command = interaction.client.slashCommands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
if(!command.autocomplete) return;
command.autocomplete(interaction);
} catch (error) {
console.error(error);
}
const event: BotEvent = {
enable: true,
name: "interactionCreate",
execute: (interaction: Interaction) => {
if (interaction.isChatInputCommand()) {
let command = interaction.client.slashCommands.get(
interaction.commandName
);
let cooldown = interaction.client.cooldowns.get(
`${interaction.commandName}-${interaction.user.username}`
);
if (!command) return;
if (command.cooldown && cooldown) {
if (Date.now() < cooldown) {
interaction.reply(
`You have to wait ${Math.floor(
Math.abs(Date.now() - cooldown) / 1000
)} second(s) to use this command again.`
);
setTimeout(() => interaction.deleteReply(), 5000);
return;
}
interaction.client.cooldowns.set(
`${interaction.commandName}-${interaction.user.username}`,
Date.now() + command.cooldown * 1000
);
setTimeout(() => {
interaction.client.cooldowns.delete(
`${interaction.commandName}-${interaction.user.username}`
);
}, command.cooldown * 1000);
} else if (command.cooldown && !cooldown) {
interaction.client.cooldowns.set(
`${interaction.commandName}-${interaction.user.username}`,
Date.now() + command.cooldown * 1000
);
}
command.execute(interaction);
} else if (interaction.isAutocomplete()) {
const command = interaction.client.slashCommands.get(
interaction.commandName
);
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
return;
}
try {
if (!command.autocomplete) return;
command.autocomplete(interaction);
} catch (error) {
console.error(error);
}
}
}
},
};

export default event;
export default event;
127 changes: 74 additions & 53 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,84 @@
import { ChannelType, Message } from "discord.js";
import { checkPermissions, getGuildOption, sendTimedMessage } from "../functions";
import {
checkPermissions,
getGuildOption,
sendTimedMessage,
} from "../functions";
import { BotEvent } from "../types";
import mongoose from "mongoose";

const event: BotEvent = {
name: "messageCreate",
execute: async (message: Message) => {
if (!message.member || message.member.user.bot) return;
if (!message.guild) return;
let prefix = process.env.PREFIX
if (mongoose.connection.readyState === 1) {
let guildPrefix = await getGuildOption(message.guild, "prefix")
if (guildPrefix) prefix = guildPrefix;
}

if (!message.content.startsWith(prefix)) return;
if (message.channel.type !== ChannelType.GuildText) return;

let args = message.content.substring(prefix.length).split(" ")
let command = message.client.commands.get(args[0])

if (!command) {
let commandFromAlias = message.client.commands.find((command) => command.aliases.includes(args[0]))
if (commandFromAlias) command = commandFromAlias
else return;
}

let cooldown = message.client.cooldowns.get(`${command.name}-${message.member.user.username}`)
let neededPermissions = checkPermissions(message.member, command.permissions)
if (neededPermissions !== null)
return sendTimedMessage(
`
enable: true,
name: "messageCreate",
execute: async (message: Message) => {
if (!message.member || message.member.user.bot) return;
if (!message.guild) return;
let prefix = process.env.PREFIX;
if (mongoose.connection.readyState === 1) {
let guildPrefix = await getGuildOption(message.guild, "prefix");
if (guildPrefix) prefix = guildPrefix;
}

if (!message.content.startsWith(prefix)) return;
if (message.channel.type !== ChannelType.GuildText) return;

let args = message.content.substring(prefix.length).split(" ");
let command = message.client.commands.get(args[0]);

if (!command) {
let commandFromAlias = message.client.commands.find((command) =>
command.aliases.includes(args[0])
);
if (commandFromAlias) command = commandFromAlias;
else return;
}

let cooldown = message.client.cooldowns.get(
`${command.name}-${message.member.user.username}`
);
let neededPermissions = checkPermissions(
message.member,
command.permissions
);
if (neededPermissions !== null)
return sendTimedMessage(
`
You don't have enough permissions to use this command.
\n Needed permissions: ${neededPermissions.join(", ")}
`,
message.channel,
5000
)


if (command.cooldown && cooldown) {
if (Date.now() < cooldown) {
sendTimedMessage(
`You have to wait ${Math.floor(Math.abs(Date.now() - cooldown) / 1000)} second(s) to use this command again.`,
message.channel,
5000
)
return
}
message.client.cooldowns.set(`${command.name}-${message.member.user.username}`, Date.now() + command.cooldown * 1000)
setTimeout(() => {
message.client.cooldowns.delete(`${command?.name}-${message.member?.user.username}`)
}, command.cooldown * 1000)
} else if (command.cooldown && !cooldown) {
message.client.cooldowns.set(`${command.name}-${message.member.user.username}`, Date.now() + command.cooldown * 1000)
}

command.execute(message, args)
message.channel,
5000
);

if (command.cooldown && cooldown) {
if (Date.now() < cooldown) {
sendTimedMessage(
`You have to wait ${Math.floor(
Math.abs(Date.now() - cooldown) / 1000
)} second(s) to use this command again.`,
message.channel,
5000
);
return;
}
message.client.cooldowns.set(
`${command.name}-${message.member.user.username}`,
Date.now() + command.cooldown * 1000
);
setTimeout(() => {
message.client.cooldowns.delete(
`${command?.name}-${message.member?.user.username}`
);
}, command.cooldown * 1000);
} else if (command.cooldown && !cooldown) {
message.client.cooldowns.set(
`${command.name}-${message.member.user.username}`,
Date.now() + command.cooldown * 1000
);
}
}

export default event
command.execute(message, args);
},
};

export default event;
21 changes: 11 additions & 10 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Client } from "discord.js";
import { BotEvent } from "../types";
import { color } from "../functions";

const event : BotEvent = {
name: "ready",
once: true,
execute: (client : Client) => {
console.log(
color("text", `💪 Logged in as ${color("variable", client.user?.tag)}`)
)
}
}
const event: BotEvent = {
enable: true,
name: "ready",
once: true,
execute: (client: Client) => {
console.log(
color("text", `💪 Logged in as ${color("variable", client.user?.tag)}`)
);
},
};

export default event;
export default event;
Loading