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

248
Views
I'm getting an error in making avatar bot in discord.js

I wanted to make a command for my bot that returns the user avatar, but I am getting an error:

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async TextChannel.send (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
  method: 'post',
  path: '/channels/885608990418010202/messages',
  code: 50006,
  httpStatus: 400,
  requestData: {
    json: {
      content: undefined,
      tts: false,
      nonce: undefined,
      embeds: undefined,
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: undefined,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}

My code:

module.exports = {
    name: 'avatar',
    aliases: ['icon', 'pfp', 'profilepic'],
    permissions: [],
    cooldown: 5,
    description: '!',

    execute(message, args, client, Discord) {

        if (!message.mentions.users.size) {
            return message.channel.send(`**آواتار شما:** ${message.author.displayAvatarURL({ dynamic: true })}`);
        }

        const avatar_list = message.mentions.users.map(user => {
            return ` آواتار**<@${user.id}>** ${user.displayAvatarURL({ dynamic: true })}`;
        });

        message.channel.send(avatar_list);
    }
}

I am using Discord.js v13, node 16

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Collection#map returns an array and you try to send that. As you can only send a string, you can join the returned array using the Array#join method:

const avatar_list = message.mentions.users.map((user) => {
  return ` آواتار**<@${user.id}>** ${user.displayAvatarURL({ dynamic: true })}`;
});

message.channel.send(avatar_list.join('\n'));
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!