Files
discordeno/site/docs/amethyst/exampleBot.md
Jonathan Ho a8a89d4b16 feat(Bigbot): added docker-compose (#2538)
* chore: fix script extension

* chore: remove extention

* fix: at least it run can now

* chore: fix dev script

* refactor: change to use env file for config

* chore: update readme

* refactor: put dotenv to top

* feat: add docker and influxdb

* chore: disable deno fmt on bigbot node_modules

* style: deno fmt

* style: deno fmt after upgrade deno

* chore: remove dev console.log

* chore: reverse the influxdb env

* chore: limit the influxdb to localhost

* refactor: seperate build process

* chore: add user pass docs

* refactor: route all to handler

* fix: skip if webhook not exist

* fix: change to use runMethod for send response

* chore: gateway don't depend on bot

* fix: skip if webhook not exist

* fix: first command and error reply not sending

* fix: add try catch to error reply

* fix: reverse interactive.reply

* feat: add fetch analytics to bot process
2022-10-22 07:28:33 -05:00

71 lines
1.9 KiB
Markdown

---
sidebar_position: 3
---
# Lets Create a simple bot in Node.js
- **Step 1**: Create a typescript project with index.ts as main file.
- **Step 2**: Installing packages. Install following packages.
```bash
npm i @thereallonewolf/amethystframework
```
- **Step 3**: Create a index.ts file.
- **Step 4**: Add following code in index.ts file, replacing TOKEN with your bot token.
```ts
import { ActivityTypes, Bot, createBot, GatewayIntents, startBot } from "discordeno";
import { enableCachePlugin, enableCacheSweepers } from "discordeno/cache-plugin";
import { AmethystBot, Context, enableAmethystPlugin } from "@thereallonewolf/amethystframework";
config();
let baseClient = createBot({
token: "TOKEN",
intents: GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIntents.MessageContent,
});
//@ts-ignore
let client = enableAmethystPlugin(enableCachePlugin(baseClient), {
botMentionAsPrefix: true,
prefix: "!", //Can be a function or a string.
ignoreBots: false,
});
enableCacheSweepers(client);
client.on("ready", () => {
console.log("I am up and running");
});
client.amethystUtils.createCategory({
name: "general",
description: "My general commands",
uniqueCommands: true,
default: "",
});
client.amethystUtils.createCommand({
name: "ping",
description: "Pong!",
commandType: ["application", "message"],
category: "general",
args: [],
async execute(bot: AmethystBot, ctx: Context) {
ctx.reply({ content: "Pong!" });
},
});
client.amethystUtils.updateSlashCommands();
startBot(client);
```
- **Step 5**: Invite your bot and compile index.ts and run it. Then you can use `/general ping` or `!ping`
- **Step 6**: Useful links:
1. Command Options can be found
[here](https://github.com/AmethystFramework/framework/blob/master/src/types/commandOptions.ts).
2. Category Options [here](https://github.com/AmethystFramework/framework/blob/master/src/types/categoryOptions.ts)
3. Full [Documentation](https://deno.land/x/amethyst)