Home > Blockchain >  Discord.js | interaction.reply is not a function [SlashCommand][Typescript]
Discord.js | interaction.reply is not a function [SlashCommand][Typescript]

Time:11-11

I am making a /ping command in my bot, following the discordjs guide, but when I use the command, I get an error:

TypeError: interaction.reply is not a function
    at Object.<anonymous> (C:\Users\timda\code\discord bot\bot-data\commands\ping.ts:8:15)
    at Generator.next (<anonymous>)
    at C:\Users\timda\code\discord bot\bot-data\commands\ping.ts:8:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\timda\code\discord bot\bot-data\commands\ping.ts:4:12)
    at Object.execute (C:\Users\timda\code\discord bot\bot-data\commands\ping.ts:18:16)   
    at C:\Users\timda\code\discord bot\main.ts:43:18
    at Generator.next (<anonymous>)
    at C:\Users\timda\code\discord bot\main.ts:8:71
    at new Promise (<anonymous>)

This is the /ping commands code:

import { SlashCommandBuilder } from 'discord.js';

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!'),
    async execute(interaction: { reply: (arg0: string) => any }) {
        console.log(interaction);
        interaction.reply('Pong!');
    },
};

And here is the code in my main file that loads in the SlashCommand files:

import fs from 'node:fs';
import path from 'node:path';
import { Client, Collection, GatewayIntentBits, Partials, REST, Routes } from 'discord.js';
import { clientId, token } from './config.json';

const client = new Client({ 
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent],
    partials: [Partials.Message, Partials.Channel],
    presence: { status: 'online', activities: [{ name: 'you            
  • Related