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

347
Visualizações
Discord.js - Get a user by ID or mention
if (!message.mentions.members.first() && !(args[0])) return message.channel.send(`<@${message.author.id}>: ${insultList[Math.floor(Math.random() * insultList.length)]}`);

const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]);

if (!user) return message.inlineReply(new Discord.MessageEmbed().setColor("D9B3FF").setTitle("Error").setDescription("User not found."));

message.channel.send(`${user}: ${insultList[Math.floor(Math.random() * insultList.length)]}`);

An !insult command; insultList being an array of strings. However, calling the command with user IDs (of guild members) only occasionally works; it usually returns User not found. Everything else works as intended.

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

0

user will return false if the id of args[0] corresponds to an uncached member.

  1. Use GuildMemberManager#fetch() to fetch the member if they were not mentioned
  2. Use (GuildMember|User)#toString() to parse member objects into mentions, no need to build them from scratch (<@id>)
const insult = insultList[Math.floor(Math.random() * insultList.length)];

if (!message.mentions.members.first() && !(args[0])) return message.channel.send(`${message.author.toString()}: ${insult}`);

try {
   const user = message.mentions.members.first() || (await message.guild.members.fetch(args[0]));
   if (!user) return message.inlineReply(new Discord.MessageEmbed().setColor("D9B3FF").setTitle("Error").setDescription("User not found."));

   message.channel.send(`${user.toString()}: ${insult}`);
} catch (err) {
   console.error(err);
}

Ensure you have the Guild Member's Intent enabled and you make your parent function is asynchronous for this example. Otherwise resolve the promise of .fetch() with callbacks.

about 4 years ago · Juan Pablo Isaza Relatório

0

have you tried mentioning the user with their id? like this: <@00000000>

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