@mallusrgreat/djs-context
v1.0.7
Published
This package helps you create a combination of a chat input command interaction and a message. You can use properties available to both of them.
Downloads
3
Readme
DJS Context
This package helps you create a combination of a chat input command interaction and a message. You can use properties available to both of them.
const { Context } = require("@mallusrgreat/djs-context");
// or
import { Context } from "@mallusrgreat/djs-context";
client.on("messageCreate", (msg) => {
if (!msg.content.toLowerCase().startsWith("!ping")) return;
const context = new Context(msg);
handlePingCommand(context);
});
client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "ping")
return;
const context = new Context(interaction);
handlePingCommand(context);
});
async function handlePingCommand(context) {
const replied = await context.reply("Pinging...");
// This line of code makes use of the "ms" npm package.
const time = ms(replied.createdTimestamp - context.createdTimestamp);
await context.editReply(`Pong! ${time}`);
}