slash cmd

how to add slash cmd
Solution:
restart the bot or call commandStore#loadAll
Jump to solution
9 Replies
Favna
Favna3mo ago
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
S A H i L
S A H i LOP3mo ago
commands are loading but bot is not responding
Favna
Favna3mo ago
Need more info really...
Spinel
Spinel3mo ago
When asking for help, make sure to provide as much detail as possible. What have you tried so far? Do you have stack traces that you can show us? What are you trying to achieve? Try to answer these questions and others, so we do not have to ask for them afterwards. - For a good guide on how to ask questions, see the instructions that StackOverflow gives. You should try to always follow these guidelines. - For an excellent video that shows how not to ask technical questions, watch this YouTube video by LiveOverflow. - Asking technical questions (Clarkson) - How to ask questions the smart way (Raymond)
S A H i L
S A H i LOP3mo ago
index,,js
import { GatewayIntentBits, Partials } from 'discord.js';
import { SapphireClient } from '@sapphire/framework';
import dotenv from 'dotenv';

dotenv.config();

const client = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.Reaction,
Partials.User,
Partials.GuildMember,
],
loadMessageCommandListeners: true,
baseUserDirectory: './commands',
});

client.login(process.env.DISCORD_TOKEN)
.then(() => console.log('Logged in successfully!'))
.catch(console.error);

export default client;

import { GatewayIntentBits, Partials } from 'discord.js';
import { SapphireClient } from '@sapphire/framework';
import dotenv from 'dotenv';

dotenv.config();

const client = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.Reaction,
Partials.User,
Partials.GuildMember,
],
loadMessageCommandListeners: true,
baseUserDirectory: './commands',
});

client.login(process.env.DISCORD_TOKEN)
.then(() => console.log('Logged in successfully!'))
.catch(console.error);

export default client;

import { Command } from "@sapphire/framework";

export class PingCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: "ping",
description: "Replies with Pong and latency information.",
aliases: ["pong"],
preconditions: ["GuildOnly"],
});
}

async messageRun(message) {
const msg = await message.channel.send("Ping?");
const content = `Pong from JavaScript! Bot Latency ${Math.round(
this.container.client.ws.ping
)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`;
return msg.edit(content);
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand(
(builder) =>
builder
.setName(this.name)
.setDescription(this.description),
);
}

async chatInputRun(interaction) {
const msg = await interaction.reply({
content: "Ping?",
withResponse: true,
});

const content = `Pong from JavaScript! Bot Latency ${Math.round(
this.container.client.ws.ping
)}ms. API Latency ${
msg.createdTimestamp - interaction.createdTimestamp
}ms.`;

return interaction.editReply(content);
}
}
import { Command } from "@sapphire/framework";

export class PingCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: "ping",
description: "Replies with Pong and latency information.",
aliases: ["pong"],
preconditions: ["GuildOnly"],
});
}

async messageRun(message) {
const msg = await message.channel.send("Ping?");
const content = `Pong from JavaScript! Bot Latency ${Math.round(
this.container.client.ws.ping
)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`;
return msg.edit(content);
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand(
(builder) =>
builder
.setName(this.name)
.setDescription(this.description),
);
}

async chatInputRun(interaction) {
const msg = await interaction.reply({
content: "Ping?",
withResponse: true,
});

const content = `Pong from JavaScript! Bot Latency ${Math.round(
this.container.client.ws.ping
)}ms. API Latency ${
msg.createdTimestamp - interaction.createdTimestamp
}ms.`;

return interaction.editReply(content);
}
}
ping ready.js
import { Listener } from '@sapphire/framework';

export class ReadyListener extends Listener {
run(client) {
const { username, id } = client.user;
this.container.logger.info(`Successfully logged in as ${username} (${id})`);
}
}
import { Listener } from '@sapphire/framework';

export class ReadyListener extends Listener {
run(client) {
const { username, id } = client.user;
this.container.logger.info(`Successfully logged in as ${username} (${id})`);
}
}
S A H i L
S A H i LOP3mo ago
No description
Favna
Favna3mo ago
Remove baseUserDirectory, not only is it an advanced option you are unlikely to need at all, you're also using it incorrectly. See the big red block at the start of the guide. As for message commands, you need to define your prefix.
S A H i L
S A H i LOP3mo ago
how to refresh old cmds slash outdated
Solution
Favna
Favna3mo ago
restart the bot or call commandStore#loadAll

Did you find this page helpful?