Created
March 11, 2019 01:13
-
-
Save Xetera/b742ff3782d1c46c58ff3683ea7950bf to your computer and use it in GitHub Desktop.
Helper function that makes creating functions with Akairo much less verbose
This file contains hidden or 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
import { CommandOptions, Command } from "discord-akairo"; | |
interface CreateCommand extends CommandOptions { | |
/** | |
* The exec function can be called in 3 different ways, however, | |
* Typescript doesn't seem to be able to support explicit `this` | |
* coming from external types, union types or overloads. In order to | |
* specify the `this` type the signature MUST be directly assigned | |
* in the interface | |
*/ | |
exec: (this: Command, message: Message, args: any, edited: boolean) => any; | |
id: string; | |
} | |
export const createCommand = ({ id, exec, ...rest }: CreateCommand) => class extends Command { | |
constructor() { | |
super(id, exec, rest); | |
} | |
}; |
This file contains hidden or 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
import { createCommand } from "./akairo.ts"; | |
import { Message } from "discord.js" | |
export default createCommand({ | |
id: "ping", | |
aliases: ["ping", "๐"], | |
category: "utility", | |
description: "Checks latency of the bot", | |
async exec(msg: Message) { | |
const m = await msg.channel.send("Ping...") as Message; | |
const latency = Math.round(m.createdTimestamp - msg.createdTimestamp); | |
const response = `Pong! ๐ Latency: **${latency}ms**`; | |
return m.edit(response); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment