Better docs
This commit is contained in:
parent
e3be0797be
commit
86de1d9113
6 changed files with 87 additions and 20 deletions
28
README.md
28
README.md
|
@ -1,13 +1,27 @@
|
||||||
# Minimal Bot Template
|
# Himbot
|
||||||
|
|
||||||
Just the minimum to get a working bot using interactions.
|
A discord bot written in Typescript and running on the Deno runtime.
|
||||||
|
|
||||||
Make sure to install the latest version when you use it.
|
## It's dangerous to go alone! Take this!
|
||||||
|
|
||||||
## Setup
|
- Install Deno [here](https://deno.com/manual@v1.34.1/getting_started/installation) (required)
|
||||||
|
- The [Deno VSCode Extension](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno) (recommended)
|
||||||
|
|
||||||
Just rename `.env.example` to `.env` and fill it with your bot token.
|
## Structure
|
||||||
|
|
||||||
## Run Bot
|
Commands and Events are all stored in named files within the src/commands and src/events directories respectively.
|
||||||
|
Usage and example ts files can be found in the examples folder.
|
||||||
|
|
||||||
- deno run -A mod.ts
|
To generate a new Command or Event run `deno task new:command` or `deno task new:event` respectively.
|
||||||
|
|
||||||
|
## Running Locally
|
||||||
|
|
||||||
|
- Copy .env.example and rename to .env
|
||||||
|
- Create a Discord Bot with all gateway permissions enabled
|
||||||
|
- Generate a token for this discord bot and paste it in the .env for BOT_TOKEN
|
||||||
|
- Run `deno run --allow-all mod.ts` to run locally
|
||||||
|
|
||||||
|
## Adding the bot to a server
|
||||||
|
|
||||||
|
Use the following link (replacing BOT_TOKEN with your own Token of course...) to add your bot:
|
||||||
|
https://discord.com/oauth2/authorize?client_id=BOT_TOKEN&scope=bot&permissions=8
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"dev": "deno run --watch mod.ts",
|
"dev": "deno run --watch mod.ts",
|
||||||
"start": "deno run --allow-env --allow-net --allow-read --allow-write mod.ts"
|
"start": "deno run --allow-env --allow-net --allow-read --allow-write mod.ts",
|
||||||
|
"new:command": "cp ./examples/newCommand.txt ./src/commands/newCommand.ts",
|
||||||
|
"new:event": "cp ./examples/newEvent.txt ./src/events/newEvent.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
45
examples/newCommand.txt
Normal file
45
examples/newCommand.txt
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
import {
|
||||||
|
ApplicationCommandOptionTypes,
|
||||||
|
ApplicationCommandTypes,
|
||||||
|
InteractionResponseTypes,
|
||||||
|
} from "../../deps.ts";
|
||||||
|
|
||||||
|
import { createCommand } from "./mod.ts";
|
||||||
|
|
||||||
|
// This is the command definition. Please ensure the name matches the file name
|
||||||
|
// Also, make sure the description is meaningfull
|
||||||
|
createCommand({
|
||||||
|
name: "command",
|
||||||
|
description: "This is an example command",
|
||||||
|
type: ApplicationCommandTypes.ChatInput,
|
||||||
|
scope: "Global",
|
||||||
|
options: [
|
||||||
|
// This is an option that can be sent after the command and used for input
|
||||||
|
{
|
||||||
|
type: ApplicationCommandOptionTypes.String,
|
||||||
|
name: "input",
|
||||||
|
description: "Text you would like to send to this command.",
|
||||||
|
// This will make the option required
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
execute: async (bot, interaction) => {
|
||||||
|
// In this example, we only use "input", so we just need the one item from an array of length 1.
|
||||||
|
// Options always returns an array, even if there is a single element.
|
||||||
|
const input = interaction.data?.options?.find(
|
||||||
|
(option) => option.name === "input"
|
||||||
|
);
|
||||||
|
|
||||||
|
// This is how the bot responds to interactions. In this case, it is via a reply.
|
||||||
|
await bot.helpers.sendInteractionResponse(
|
||||||
|
interaction.id,
|
||||||
|
interaction.token,
|
||||||
|
{
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: {
|
||||||
|
content: `${input?.value} was ${interaction.user.username}'s nickname in highschool.`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
15
examples/newEvent.txt
Normal file
15
examples/newEvent.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { events } from "./mod.ts";
|
||||||
|
import { logger } from "../utils/logger.ts";
|
||||||
|
|
||||||
|
// Log the event name here
|
||||||
|
const log = logger({ name: "Event: messageCreate" });
|
||||||
|
|
||||||
|
/*
|
||||||
|
The properties of events are tied to specific discord events.
|
||||||
|
Please ensure that both the event type and the property (in this case message)
|
||||||
|
accurately reflect what you want to listen for.
|
||||||
|
*/
|
||||||
|
events.exampleEvent = (bot, message) => {
|
||||||
|
// In this example, the message contents are simply being logged
|
||||||
|
log.info(`${message.tag}: ${message.content}`);
|
||||||
|
};
|
|
@ -3,12 +3,11 @@ import {
|
||||||
ApplicationCommandTypes,
|
ApplicationCommandTypes,
|
||||||
InteractionResponseTypes,
|
InteractionResponseTypes,
|
||||||
} from "../../deps.ts";
|
} from "../../deps.ts";
|
||||||
import {
|
|
||||||
humanizeMilliseconds,
|
|
||||||
snowflakeToTimestamp,
|
|
||||||
} from "../utils/helpers.ts";
|
|
||||||
import { createCommand } from "./mod.ts";
|
import { createCommand } from "./mod.ts";
|
||||||
|
|
||||||
|
// Thanks for the bot name idea Wryna!
|
||||||
|
|
||||||
createCommand({
|
createCommand({
|
||||||
name: "wryna",
|
name: "wryna",
|
||||||
description: "What was your nickname in highschool?",
|
description: "What was your nickname in highschool?",
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
import { events } from "./mod.ts";
|
|
||||||
import { logger } from "../utils/logger.ts";
|
|
||||||
|
|
||||||
const log = logger({ name: "Event: messageCreate" });
|
|
||||||
|
|
||||||
events.messageCreate = (bot, message) => {
|
|
||||||
log.info(`${message.tag}: ${message.content}`);
|
|
||||||
};
|
|
Loading…
Add table
Reference in a new issue