Let's learn how to build a discord bot Deno style!
Foe this we will need a libary, for this we have the great libary harmony, which let's us interact with the discord API.
But to make things easier we will use D-rex. D-rex is a framework built on harmony that let's u write commands and hooks for messages.
First things first we will need to import the client:
import { app } from 'https://deno.land/x/drex/mod.ts';
Now we that we have the client object we will need to create a client and register our command. Our bot will have a simple ping command:
const client = app(['!']) / creates app and supplies list of prefixes
client.command({{ name: 'ping'}))
Next we can register aliases, this step is not required
client.command({{ name: 'ping', aliases: ['p', 'test']})
Now all we need is to create the handler:
const ping = (message) => {
message.reply('pong from deno and D-rex')
}
client.command({{ name: 'ping', aliases: ['p', 'test'], handler: ping)
Now we have a client. and a command last step is to start the bot with the API key:
client.listen('your API key')
We did it, now we have a running bot made with deno and js/ts!!
import { app } from 'https://deno.land/x/drex/mod.ts';
const client = app(['!']) / creates app and supplies list of prefixes
const ping = (message) => {
message.reply('pong from deno and D-rex')
}
client.command({{ name: 'ping', aliases: ['p', 'test'], handler: ping)
client.listen('your API key')
Top comments (0)