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.
user will return false if the id of args[0] corresponds to an uncached member.
<@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.
have you tried mentioning the user with their id? like this: <@00000000>