-
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.
- Loading branch information
Matt Cavanagh
committed
May 11, 2023
1 parent
5a61b30
commit ca63c38
Showing
10 changed files
with
496 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,2 @@ | ||
node_modules | ||
.idea |
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,19 @@ | ||
{ | ||
"name": "digletbot", | ||
"version": "1.0.0", | ||
"description": "Typescript bot that serves the Dignity of War community", | ||
"main": "index.js", | ||
"author": "Matt Cavanagh <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "ts-node src/bot.ts" | ||
}, | ||
"dependencies": { | ||
"discord.js": "^14.11.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.1.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.4" | ||
} | ||
} |
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 @@ | ||
import { Client } from "discord.js"; | ||
import ready from "./listeners/ready"; | ||
import interactionCreate from "./events/InteractionCreate"; | ||
|
||
console.log("Bot is starting..."); | ||
|
||
const token = "MTEwNjMxODg4OTMxNjUyODE3OA.GCZ18R.WJLOW-YfBwDdJnpKlRW1L0PlwAwwTtgDELoF0s" | ||
|
||
const client = new Client({ | ||
intents: [] | ||
}); | ||
|
||
// Declare listeners | ||
ready(client); | ||
|
||
// Declare event handlers | ||
interactionCreate(client); | ||
|
||
|
||
client.login(token); | ||
|
||
console.log(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,4 @@ | ||
import { CommandInterface } from "./interfaces/CommandInterface"; | ||
import { HelloCommand } from "./commands/HelloCommand"; | ||
|
||
export const Commands: CommandInterface[] = [HelloCommand]; |
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,16 @@ | ||
import {Client, CommandInteraction, ApplicationCommandType} from "discord.js"; | ||
import { CommandInterface } from "../interfaces/CommandInterface"; | ||
|
||
export const HelloCommand: CommandInterface = { | ||
name: "hello", | ||
description: "Returns a greeting", | ||
type: ApplicationCommandType.ChatInput, | ||
run: async (client: Client, interaction: CommandInteraction) => { | ||
const content = "Hello there!"; | ||
|
||
await interaction.followUp({ | ||
ephemeral: true, | ||
content | ||
}); | ||
} | ||
}; |
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,23 @@ | ||
import {BaseInteraction, Client, CommandInteraction, Interaction} from "discord.js"; | ||
import {Commands} from "../commands"; | ||
|
||
export default (client: Client): void => { | ||
client.on("interactionCreate", async (interaction: Interaction) => { | ||
if (interaction.isCommand()) { | ||
await handleSlashCommand(client, interaction); | ||
} | ||
}); | ||
}; | ||
|
||
const handleSlashCommand = async (client: Client, interaction: CommandInteraction): Promise<void> => { | ||
const slashCommand = Commands.find(c => c.name === interaction.commandName); | ||
|
||
if (!slashCommand) { | ||
interaction.followUp({ content: "An error has occurred" }); | ||
return; | ||
} | ||
|
||
await interaction.deferReply(); | ||
|
||
slashCommand.run(client, interaction); | ||
}; |
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,5 @@ | ||
import { CommandInteraction, ChatInputApplicationCommandData, Client } from "discord.js"; | ||
|
||
export interface CommandInterface extends ChatInputApplicationCommandData { | ||
run: (client: Client, interaction: CommandInteraction) => void; | ||
} |
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,14 @@ | ||
import { Client } from "discord.js"; | ||
import {Commands} from "../commands"; | ||
|
||
export default (client: Client): void => { | ||
client.on("ready", async () => { | ||
if (!client.user || !client.application) { | ||
return; | ||
} | ||
|
||
await client.application.commands.set(Commands); | ||
|
||
console.log(`${client.user.username} is online`); | ||
}); | ||
}; |
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,33 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "commonjs", | ||
"rootDir": "./src/", | ||
"outDir": "./dist/", | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"importHelpers": true, | ||
"experimentalDecorators": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"removeComments": true, | ||
"typeRoots": [ | ||
"node_modules/@types" | ||
], | ||
"sourceMap": false, | ||
"baseUrl": "./" | ||
}, | ||
"files": [ | ||
"src/Bot.ts" | ||
], | ||
"include": [ | ||
"./**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
], | ||
} |
Oops, something went wrong.