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
Favna3mo 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
Favna3mo ago
currently you're only implementing message commands
Favna
Favna3mo 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
Devvvvvv3mo 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
Favna3mo ago
you'll be doing something wrong. Please show your current code. you can also generate a starter template using @sapphire/cli
Devvvvvv
Devvvvvv3mo 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
Favna3mo 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
Devvvvvv3mo ago
oh my bad i was refering to index.js i start the bot using nodemon
Favna
Favna3mo ago
nodemon src/index.js?
Devvvvvv
Devvvvvv3mo ago
just nodemon
Favna
Favna3mo ago
try changing it to nodemon . instead of nodemon index.js
Devvvvvv
Devvvvvv3mo ago
same logs as before let me check if the slash command appears
Favna
Favna3mo ago
it would have logged if it did so no it doesnt
Devvvvvv
Devvvvvv3mo ago
nope still dead logged what exatly???
Favna
Favna3mo 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
Want results from more Discord servers?
Add your server