Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!