Skip to content

Commit

Permalink
[Fix] fixed a bug where the avatar command would crash the bot if the…
Browse files Browse the repository at this point in the history
… user had no avatar
  • Loading branch information
naseif committed Oct 5, 2021
1 parent 9567a8c commit 66ed8a5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions commands/Misc/avatar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { getUserFromMention } = require("../../modules/getUserFromMention");

module.exports = {
name: "avatar",
args: true,
description: "Sends the user's avatar or a mentioned users avatar",
usage: "avatar <user (optional)>",
async run(message, args, client) {
const user = getUserFromMention(args[0], client) || message.member.user;

if (!user.avatarURL())
return await message.channel.send("This user has no avatar!");

const embed = {
color: "#9dcc37",
fields: [
{
name: "User Avatar For: ",
value: `${user}`,
inline: true,
},
],
image: {
url: `${user.avatarURL({
format: "png",
dynamic: true,
size: 1024,
})}`,
},
timestamp: new Date(),
};

await message.channel.send({ embeds: [embed] });
},
data: new SlashCommandBuilder()
.setName("avatar")
.setDescription("Sends the user's avatar")
Expand All @@ -11,6 +43,9 @@ module.exports = {
await interaction.deferReply();
const user = interaction.options.getUser("user");

if (!user.avatarURL())
return await interaction.followUp(`This user has no avatar!`);

const embed = {
color: "#9dcc37",
fields: [
Expand Down

0 comments on commit 66ed8a5

Please sign in to comment.