Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "DiscordAPIError[10007]: Unknown Member" in /avatar #800

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/discord/commands/global/d.avatar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
SlashCommandBuilder,
DiscordAPIError,
} from 'discord.js';

import { SlashCommand } from '../../@types/commandDef';
Expand Down Expand Up @@ -32,15 +33,22 @@ export const dAvatar: SlashCommand = {
// log.debug(F, `user: ${JSON.stringify(user, null, 2)}`);
// log.debug(F, `user.id: ${user.id}`);

const member = await interaction.guild.members.fetch(user.id);

// log.debug(F, `member: ${JSON.stringify(member, null, 2)}`);

const embed = embedTemplate()
.setTitle(`${member.displayName}'s Profile Picture`)
.setImage(`${member.displayAvatarURL()}?size=4096`);
await interaction.editReply({ embeds: [embed] });
return true;
try {
const member = await interaction.guild.members.fetch(user.id);
// log.debug(F, `member: ${JSON.stringify(member, null, 2)}`);
const embed = embedTemplate()
.setTitle(`${member.displayName}'s Profile Picture`)
.setImage(`${member.displayAvatarURL()}?size=4096`);
await interaction.editReply({ embeds: [embed] });
return true;
} catch (err) {
if ((err as DiscordAPIError).code === 10007) {
await interaction.editReply({ content: 'This command can only be used on a member of the current guild.' });
return false;
}
}
// If this line is reached, then there was a problem.
return false;
},
};

Expand Down
Loading