slashcommand wont appear

Tried to implement slash command but it wont show up. The bot is invited with the bot and application.commands scope and it still wont work. ping.js
const { Command } = require('@sapphire/framework');

class PingCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'ping',
aliases: ['pong'],
description: 'ping pong',
});
}

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);
}
}
module.exports = {
PingCommand,
};
const { Command } = require('@sapphire/framework');

class PingCommand extends Command {
constructor(context, options) {
super(context, {
...options,
name: 'ping',
aliases: ['pong'],
description: 'ping pong',
});
}

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);
}
}
module.exports = {
PingCommand,
};
index.js
const { SapphireClient } = require('@sapphire/framework');
const { GatewayIntentBits } = require('discord.js');
require('dotenv').config();

const client = new SapphireClient({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],
loadMessageCommandListeners: true,
});

client.login(process.env.TOKEN);
const { SapphireClient } = require('@sapphire/framework');
const { GatewayIntentBits } = require('discord.js');
require('dotenv').config();

const client = new SapphireClient({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],
loadMessageCommandListeners: true,
});

client.login(process.env.TOKEN);
26 Replies
Favna
Favna8mo ago
Please follow the guide for creating a slash command: https://sapphirejs.dev/docs/Guide/getting-started/creating-a-basic-app-command
Sapphire Framework
Creating a basic slash command | Sapphire
This section covers the absolute minimum for setting up a slash command. We have an entire "Application Commands"
Favna
Favna8mo ago
currently you're only implementing message commands
Favna
Favna8mo ago
message commands are the old style of !prefix command, what your screenshot is looking for is called a context menu command https://sapphirejs.dev/docs/Guide/getting-started/creating-a-basic-context-menu-command
Sapphire Framework
Creating a basic context menu command | Sapphire
This section covers the absolute minimum for setting up a message context menu command. We have an entire
Devvvvvv
DevvvvvvOP8mo ago
Ii just pasted the code to see if it works but it still wont update the slash command is it supposed to take time or am i doing something wrong?
Favna
Favna8mo ago
you'll be doing something wrong. Please show your current code. you can also generate a starter template using @sapphire/cli
Devvvvvv
DevvvvvvOP8mo ago
ping.js
const { isMessageInstance } = require('@sapphire/discord.js-utilities');
const { Command } = require('@sapphire/framework');

class PingCommand extends Command {
constructor(context, options) {
super(context, { ...options });
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName('ping')
.setDescription('Ping bot to see if it is alive')
);
}

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

if (isMessageInstance(msg)) {
const diff = msg.createdTimestamp - interaction.createdTimestamp;
const ping = Math.round(this.container.client.ws.ping);
return interaction.editReply(
`Pong 🏓! (Round trip took: ${diff}ms. Heartbeat: ${ping}ms.)`
);
}

return interaction.editReply('Failed to retrieve ping :(');
}
}
module.exports = {
PingCommand,
};
const { isMessageInstance } = require('@sapphire/discord.js-utilities');
const { Command } = require('@sapphire/framework');

class PingCommand extends Command {
constructor(context, options) {
super(context, { ...options });
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName('ping')
.setDescription('Ping bot to see if it is alive')
);
}

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

if (isMessageInstance(msg)) {
const diff = msg.createdTimestamp - interaction.createdTimestamp;
const ping = Math.round(this.container.client.ws.ping);
return interaction.editReply(
`Pong 🏓! (Round trip took: ${diff}ms. Heartbeat: ${ping}ms.)`
);
}

return interaction.editReply('Failed to retrieve ping :(');
}
}
module.exports = {
PingCommand,
};
main file is the same and this is my project structure
Favna
Favna8mo ago
by "main file is the same" what is the main file? are you referring to you main in package.json? how do you start the bot?
Devvvvvv
DevvvvvvOP8mo ago
oh my bad i was refering to index.js i start the bot using nodemon
Favna
Favna8mo ago
nodemon src/index.js?
Devvvvvv
DevvvvvvOP8mo ago
just nodemon
Favna
Favna8mo ago
try changing it to nodemon . instead of nodemon index.js
Devvvvvv
DevvvvvvOP8mo ago
same logs as before let me check if the slash command appears
Favna
Favna8mo ago
it would have logged if it did so no it doesnt
Devvvvvv
DevvvvvvOP8mo ago
nope still dead logged what exatly???
Favna
Favna8mo ago
can you try to generate a template with @sapphire/cli? I can't quite tell what is wrong at a glance but if you generate with the template it must be right
Devvvvvv
DevvvvvvOP8mo ago
i shall try this then
Favna
Favna8mo ago
usage is also documented on the website
Devvvvvv
DevvvvvvOP8mo ago
i see
Favna
Favna8mo ago
ApplicationCommandRegistries: Initializing...
ApplicationCommandRegistries(BulkOverwrite) Successfully overwrote global application commands. The application now has 10 global commands
ApplicationCommandRegistries: Took 773ms to initialize.
ApplicationCommandRegistries: Initializing...
ApplicationCommandRegistries(BulkOverwrite) Successfully overwrote global application commands. The application now has 10 global commands
ApplicationCommandRegistries: Took 773ms to initialize.
this is for @Dragonite . See how there is a line between initializing and the time it took.
Devvvvvv
DevvvvvvOP8mo ago
oh yes this never came up also what was the cli command to create a template again? i am unable to find it on docs
Favna
Favna8mo ago
https://sapphirejs.dev/docs/Guide/CLI/getting-started please put in a little bit of effort... the header "official Sapphire CLI" really shouldn't be that hard to find
Sapphire Framework
Getting Started | Sapphire
Installation
Devvvvvv
DevvvvvvOP8mo ago
no i did find this do you mean the command to install the packages for saphhirejs? or like a fullblown starter project template
Favna
Favna8mo ago
I hate doing this just as much as people hate receiving it but ...
Devvvvvv
DevvvvvvOP8mo ago
oh god sorry had problems with teh cli too so i just gave up and then figured out that i forgot the defaultPrefix: '!' parameter in the client object :) normal commands work when i do this still gotta try slash commands and sub commands too
Favna
Favna8mo ago
the cli should create a ready made template, make sure when you invite your bot you add the application commands scope.
Devvvvvv
DevvvvvvOP8mo ago
yes yes did taht the logs of the cli said that it registered 4 commands but none of them worked in the server
Want results from more Discord servers?
Add your server