@akki256/discord-interaction
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

@akki256/discord-interaction

Module for easier handling of discord interaction

Installation

npm install '@akki256/discord-interaction'
yarn add '@akki256/discord-interaction'

Usage

index.js

const discord = require('discord.js');
const client = new discord.Client({
	/* options */
});
const { DiscordInteractions, ErrorCodes, InteractionsError } = require('@akki256/discord-interaction');
const interactions = new DiscordInteractions(client);
interactions.loadInteractions('./interactions');

client.on('ready',() => {
	interactions.registerCommands({ syncWithCommand: true });
})

client.on('interactionCreate', interaction => {
	interactions.run(interaction).catch(error => {
		if (error instanceof InteractionsError && error.code === ErrorCodes.CommandHasCoolTime) {
			if(interaction.isRepliable()) interaction.reply({ content: 'This command is currently on cool time.', ephemeral: true })
		}
		console.error(error);
	});
})

client.login('token');

interactions/ping.js

const { ChatInput } = require('@akki256/discord-interaction');

const pingCommand = new ChatInput({
	name: 'ping',
	description: 'pong!'
}, interaction => {
	interaction.reply('pong!')
})

module.exports = [ pingCommand ];

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i @akki256/discord-interaction

Weekly Downloads

32

Version

3.1.1

License

MIT License

Unpacked Size

29.9 kB

Total Files

17

Last publish

Collaborators

  • akki256