Can someone please tell me why my slash command isn't working? The code compiles fine, and the bot runs, but the slash command isn't working. The code is found on this website.
https://sabe.io/tutorials/how-to-build-discord-bot-typescript
22 messages · Page 1 of 1 (latest)
Can someone please tell me why my slash command isn't working? The code compiles fine, and the bot runs, but the slash command isn't working. The code is found on this website.
https://sabe.io/tutorials/how-to-build-discord-bot-typescript
@ivory mulch I didn't get any error. It's just not working.
I did register the command.
hm
@ivory mulch Wait, I sent the wrong link.
@ivory mulch I meant to send this link. https://dev.to/fellipeutaka/creating-your-first-discord-bot-using-typescript-1eh6
@potent python Please do not ping someone on every message.
?...
There is only so much i can help you with, try messing with the code, and you can add breakpoints and stuff
and see if it actually runs it
When you @username someone, it's a ping. You don't need to do it it three times within a minute.
Without any actual reference to where it’s breaking, i can’t really help tbh.
I know what a ping is. I'm confused by your comment, though, as Object never said not to do it.
How would I restructure this code
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
export const data = new SlashCommandBuilder()
.setName("ping")
.setDescription("Replies with Pong!");
export async function execute(interaction: CommandInteraction) {
return interaction.reply("Pong!");
}
like such:
import { CommandInteraction, Client } from "discord.js";
import { Command } from "../Command";
export const Hello: Command = {
name: "hello",
description: "Returns a greeting",
type: "CHAT_INPUT",
run: async (client: Client, interaction: CommandInteraction) => {
const content = "Hello there!";
await interaction.followUp({
ephemeral: true,
content
});
}
};
i believe slash command builder already does most of the formatting
look at your slash command handler and see if it’s running
@ivory mulch I think I figured out the issue. When I run, "node index.js," the bot runs. However, when I try to run it from the command, "npm start dev," I get an error: "dotenv_1.dotenv.config(); ^ TypeError: Cannot read properties of undefined (reading 'config')."
You are using require(‘dotenv’).config() right?
maybe wrong quotes but yk
import * as dotenv from 'dotenv';
dotenv.config();
const { DISCORD_TOKEN, DISCORD_CLIENT_ID } = process.env;
if (!DISCORD_TOKEN || !DISCORD_CLIENT_ID) {
throw new Error("Missing environment variables");
}
export const config = {
DISCORD_TOKEN,
DISCORD_CLIENT_ID,
};
do “import dotenv from ‘dotenv’;” instead