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

122
Visualizações
How to .deferReply to specified channel?

How can I have it so that the bot sends a message to a specific channel, while using .deferReply and .editReply? Currently, I'm getting an error saying that suggestionChannel.deferReply is not a function. Here's my code:

const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");

module.exports = {
  data: new SlashCommandBuilder()
    .setName("suggest")
    .setDescription("Send your suggestion to the specified channel")
    .addStringOption((option) =>
      option
        .setName("suggestion")
        .setDescription("Your suggestion")
        .setRequired(true)
    ),
  async execute(interaction, client) {
    var suggestionChannelID = "900982140504793109";
    var suggestionChannel = client.channels.cache.get(suggestionChannelID);
    const embed = new MessageEmbed()
      .setColor("#0099ff")
      .setTitle(`New suggestion by ${interaction.member.displayName}`)
      .setDescription(`${interaction.options.getString("suggestion")}`);
    await suggestionChannel.deferReply();
    await suggestionChannel
      .editReply({
        embeds: [embed],
      })
      .then(function (interaction) {
        interaction.react(`👍`).then(interaction.react(`👎`));
      });
  },
};

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

How can I have it so that the bot sends a message to a specific channel, while using .deferReply and .editReply?

Well, the short answer is; you can't. But you can do this:

As the error already says, deferReply() is not a method of the TextBasedChannels class, defined by your suggestionChannel.

Instead, try sending a message to the channel instead of replying. Replies can only be executed in the interaction's channel:

var suggestionChannelID = "900982140504793109";
var suggestionChannel = client.channels.cache.get(suggestionChannelID);
const embed = new MessageEmbed()
    .setColor("#0099ff")
    .setTitle(`New suggestion by ${interaction.member.displayName}`)      
    .setDescription(`${interaction.options.getString("suggestion")}`);

// use this instead
await suggestionChannel.send({
    embeds: [embed],
});

P.S side note, deferReply() starts a 15-minute timer before the interaction expires and triggers that 'x is thinking...' text to appear when the client is calculating stuff, so try to call it as soon as possible. By default, interactions expire after 3 seconds, so if your bot fails to finish whatever it needs to accomplish within that timeframe, that interaction will fail.

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