Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

456
Visualizações
I can't send an embed with a slash command (discord.js)

So what happens is Anytime I try to send a embed with a slash command on discord.js it throws an error. Here is the "help.js" file I'm trying to send.

const { SlashCommandBuilder } = require('@discordjs/builders');

const { MessageEmbed } = require('discord.js');

const helpEmbed = {
  "type": "rich",
  "title": `Need Help?`,
  "description": `Here you go.`,
  "color": 0x00fff0
}

module.exports = {
    data: new SlashCommandBuilder()
        .setName('help')
        .setDescription('Prints a Help Message'),
    async execute(interaction) {
        await channel.send({embeds: [helpEmbed]});
    },
};

The Error:

ReferenceError: channel is not defined
    at Object.execute (C:\Users\user\Desktop\my-bot\bot-file\commands\help.js:37:3)
    at Client.<anonymous> (C:\Users\user\Desktop\my-bot\bot-file\index.js:31:17)
    at Client.emit (node:events:527:28)
    at InteractionCreateAction.handle (C:\Users\user\Desktop\my-bot\bot-file\node_modules\discord.js\src\client\actions\InteractionCreate.js:83:12)
    at Object.module.exports [as INTERACTION_CREATE] (C:\Users\user\Desktop\my-bot\bot-file\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\Users\user\Desktop\my-bot\bot-file\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\Users\user\Desktop\my-bot\bot-file\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\Users\user\Desktop\my-bot\bot-file\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\user\Desktop\my-bot\bot-file\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:527:28)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are getting this error because the variable channel has not been defined before you used it. Instead you can use interaction.channel.send() if you want to send the help embed to the channel where the user used the slash command or optionally you can fetch the channel by either using the id or the channel name and then send it.

1st option: (If you want to send the embed to the channel where the user used the slash command)

async execute(interaction) {
    await interaction.channel.send({embeds: [helpEmbed]});
}

2nd option: (If you want to find the channel by its id or its name)

async execute(interaction) {
    const channel = interaction.guild.channels.cache.get('channelid')
    // Or
    const channel = interaction.guild.channels.cache.find(ch => ch.name === 'channelName')
    await channel.send({embeds: [helpEmbed]});
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda