Basic Bot setup
This commit is contained in:
73
src/events/interactionCreate/handleCommands.ts
Normal file
73
src/events/interactionCreate/handleCommands.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Client, Interaction } from "discord.js";
|
||||
import { devs, testServer } from "../../../config.json"
|
||||
import getLocalCommands from "../../utils/getLocalCommands"
|
||||
import CommandInterface from "../../utils/commandInterface";
|
||||
|
||||
export default async (client: Client<true>, interaction: Interaction) => {
|
||||
if(!interaction.isChatInputCommand()) return;
|
||||
|
||||
const localCommands = await getLocalCommands() as CommandInterface[];
|
||||
|
||||
try {
|
||||
const commandObject = localCommands.find((cmd) => cmd.name == interaction.commandName);
|
||||
|
||||
if(!commandObject) return;
|
||||
|
||||
if(commandObject.devOnly){
|
||||
if(!devs.includes(interaction.user.id)) {
|
||||
interaction.reply({
|
||||
content: "Nur Developer können diesen Befehl ausführen!",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(commandObject.testOnly){
|
||||
if(!(interaction.guildId === testServer)) {
|
||||
interaction.reply({
|
||||
content: "Diese Command kann bisher nur im Hauseigenden Test-Discord genutzt werden!",
|
||||
ephemeral: true,
|
||||
})
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(commandObject.permissionsRequired?.length){
|
||||
for(const permission of commandObject.permissionsRequired){
|
||||
if(!interaction.memberPermissions?.has(permission)){
|
||||
interaction.reply({
|
||||
content: "Dir fehlen die Nötigen Berechtigungen zum Ausführen dieses Commands!",
|
||||
ephemeral: true,
|
||||
})
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(commandObject.botPermissions?.length){
|
||||
for(const permission of commandObject.botPermissions){
|
||||
const bot = interaction.guild?.members.me;
|
||||
|
||||
if(!bot?.permissions.has(permission)){
|
||||
interaction.reply({
|
||||
content: "Ich habe nicht genug Rechte um dies Auszuführen! Benötigt: " + commandObject.botPermissions,
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(commandObject.onlyServerCommand){
|
||||
if(!interaction.inGuild()){
|
||||
interaction.reply("Dieser Command kann nur in einem Server ausgefürt werden!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await commandObject.callback(client, interaction);
|
||||
} catch (error) {
|
||||
console.log(`Es gab einen Fehler den Comand auszuführen | ${error}`);
|
||||
}
|
||||
};
|
||||
52
src/events/ready/01registerCommands.ts
Normal file
52
src/events/ready/01registerCommands.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Client } from "discord.js";
|
||||
import {testServer} from "../../../config.json"
|
||||
import getApplicationCommands from "../../utils/getApplicationCommands";
|
||||
import getLocalCommands from "../../utils/getLocalCommands"
|
||||
import CommandInterface from "../../utils/commandInterface"
|
||||
import areCommandsDifferent from "../../utils/areCommandsDifferent";
|
||||
|
||||
export default async (client: Client) => {
|
||||
try {
|
||||
const localCommands = await getLocalCommands() as CommandInterface[];
|
||||
const applicationCommands = await getApplicationCommands(client as Client<true>);
|
||||
|
||||
for(const localCommand of localCommands){
|
||||
let {name, description, options} = localCommand;
|
||||
|
||||
const existingCommand = (await applicationCommands).cache.find((cmd) => cmd.name === name);
|
||||
|
||||
if(existingCommand){
|
||||
if(localCommand.deleted){
|
||||
(await applicationCommands).delete(existingCommand.id);
|
||||
console.log(`Command ${name} gelöscht!`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(areCommandsDifferent(existingCommand, localCommand)){
|
||||
(await applicationCommands).edit(existingCommand.id, {
|
||||
description,
|
||||
options
|
||||
})
|
||||
|
||||
console.log(`Command ${name} Geändert!`)
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(localCommand.deleted){
|
||||
console.log(`Überspringe registrierung von Command ${name}, da er auf geläscht gesetzt wurde!`);
|
||||
continue;
|
||||
}
|
||||
|
||||
(await applicationCommands).create({
|
||||
name,
|
||||
description,
|
||||
options,
|
||||
})
|
||||
|
||||
console.log(`Command ${name} hinzugefügt!`)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Es gab einen Fehler: ${error}`);
|
||||
}
|
||||
}
|
||||
21
src/events/ready/changeStatus.ts
Normal file
21
src/events/ready/changeStatus.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Client, ActivityType } from "discord.js";
|
||||
|
||||
const status = [ make_status("Slash Commands"), make_status("/help"), make_status("by Agione") ];
|
||||
|
||||
export default async (client: Client<true>) => {
|
||||
client.user?.setActivity(status[0]);
|
||||
|
||||
setInterval(() => {
|
||||
let random = Math.floor(Math.random() * status.length);
|
||||
client.user?.setActivity(status[random]);
|
||||
}, 10000);
|
||||
|
||||
};
|
||||
|
||||
function make_status(name: string){
|
||||
return {
|
||||
name: name,
|
||||
type: ActivityType.Streaming,
|
||||
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
||||
}
|
||||
}
|
||||
5
src/events/ready/consoleLog.ts
Normal file
5
src/events/ready/consoleLog.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Client } from "discord.js";
|
||||
|
||||
export default async (client: Client<true>) => {
|
||||
console.log(`${client.user.username} ist nun Gestartet!`)
|
||||
};
|
||||
Reference in New Issue
Block a user