npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

djs.ext.commands

v0.2.6

Published

Imitation of discord.ext.commands written in TypeScript

Downloads

4

Readme

djs.ext.commands

djs.ext.commands is imitation of discord.ext.commands written in TypeScript.
Usages are similar to original.

Installation

npm install djs.ext.commands

Quick Example

import { Formatters as Format } from 'discord.js'
import { Bot, Ctx } from 'djs.ext.commands'

class MyBot extends Bot {
	@Bot.event('ready')
	async ready() {
		console.log('I\'m ready!')
	}
	@Bot.textCommand()
	async ping(ctx: Ctx.Text) {
		ctx.send('Pong!')
	}
	@Bot.slashCommand({ argDefinitions: [ { name: 'input', type: 'string' } ] })
	async get_input(ctx: Ctx.Slash<[ 'string' ]>) {
		await ctx.send(`Input: ${Format.inlineCode(ctx.args[0])}`)
	}
}

const bot = new MyBot({ prefix: '!' })

bot.run('TOKEN')

You can find more examples in the examples directory.

Decorator?

Basically, JavaScript doesn't support decorator syntax.
If you want to use decorator syntax, you should use Babel or TypeScript, etc.

Difference with discord.ext.commands

Class syntax is recommended

Decorator syntax is only can be used in class.
So, using class syntax is recommended.
Without decorator syntax, you can write code like this:

import { Bot } from 'djs.ext.commands'

const bot = new Bot()

;(bot as any).onReady = () => {
	console.log('I\'m ready!')
}
Bot.event(bot, 'onReady')

;(bot as any).ping = (ctx: Ctx.Text) => {
	ctx.send('Pong!')
}
Bot.textCommand()(bot, 'ping')

bot.run('TOKEN')

But, as you know, this way is bad.

No automatic argument parsing without argTypes/argDefinitions option of command

Due to limit of JavaScript, arguments of listener cannot parsed automatically.
So, if you want parsed arguments, you should set argTypes/argDefinitions option yourself like this:

import { Bot, Ctx } from 'djs.ext.commands'

class MyBot extends Bot {
	@Bot.textCommand({ argTypes: [ 'number', 'number' ] })
	async sum(ctx: Ctx.Text<[ 'number', 'number' ]>) {
		const [ first, second ] = ctx.args
		ctx.send(`Sum of ${first} and ${second} is ${first + second}.`)
	}
}