Home > front end >  Discord.js cant figure how to do slashcommands
Discord.js cant figure how to do slashcommands

Time:11-06

Eh so hello. I Cant frikin figure how to build SLASH COMMANDS!!!! Tbh i dont even want to anymore but still asking (I am here for the 3d day trying to figure it out) so bruh. It is working, but it DOESN'T show the command in discord even if i type the command out it still DOESNT WORK. So anyways heres my code:

const { Server } = require('discord.io');
const Discord = require('discord.js');
const { Client, GatewayIntentBits, messageLink, InteractionResponseType } = require('discord.js');
const logger = require('winston');
const { EmbedBuilder, SlashCommandBuilder, Events } = require('discord.js');
const bot = new Discord.Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildEmojisAndStickers,
        GatewayIntentBits.GuildMessageReactions,
    ],
});

const token = "heheheha"
//text
bot.on('ready', () => { // when the bot is ready and online
    console.log('bot is now online!')
});


new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!'),
    async execute(interaction) 
    {
        await interaction.reply('Pong!');
    }

oh and also, this is my Error log

    async execute(interaction) 
          ^^^^^^^

SyntaxError: Unexpected identifier
    at compileFunction (vm:360:18)
    at wrapSafe (internal/modules/cjs/loader:1084:15)
    at Module._compile (internal/modules/cjs/loader:1119:27)
    at Module._extensions..js (internal/modules/cjs/loader:1209:10)
    at Module.load (internal/modules/cjs/loader:1033:32)
    at Module._load (internal/modules/cjs/loader:868:12)
    at executeUserEntryPoint (internal/modules/run_main:81:12)
    at <anonymous> (internal/main/run_main_module:22:47)

CodePudding user response:

First you have to create to separate JS files index.js and deployCommands.js

index.js file helps in making the bot online and handling all the events and commands whereas deployCommands.js helps in deploying your commands to the Discord servers

Go to this GitHub repo - https://github.com/devashu397/Discord.js-v14-Slash-CMD-Handler.git

CodePudding user response:

Slash command builders themselves do not house an execute function or any code for the command to run, instead they are used to refresh Discord's servers with what commands your client has.

Please read more on the topics you are asking for before asking a question.
https://discordjs.guide/creating-your-bot/command-deployment.html
https://discordjs.guide/creating-your-bot/slash-commands.html

  • Related