Dylan
DIAdiscord.js - Imagine an app
•Created by Dylan on 7/2/2024 in #djs-questions
Cannot read properties of undefined (reading 'reduce')
ah
5 replies
DIAdiscord.js - Imagine an app
•Created by Dylan on 6/10/2024 in #djs-questions
ContextMenuCommandBuilder Permissions
that helped, thanks o7
7 replies
DIAdiscord.js - Imagine an app
•Created by Dylan on 6/10/2024 in #djs-questions
ContextMenuCommandBuilder Permissions
From builders:
Here is the entire code:
const { ContextMenuCommandBuilder, PermissionFlagsBits } = require("@discordjs/builders");
const { ContextMenuCommandBuilder, PermissionFlagsBits } = require("@discordjs/builders");
const { ContextMenuCommandBuilder, PermissionFlagsBits } = require("@discordjs/builders");
const { MediaEmbed, ErrorEmbed } = require("../utils/embeds");
const { Error, Debug } = require("../utils/logging");
module.exports = {
data: new ContextMenuCommandBuilder()
.setName("View User Avatar")
.setType(2)
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
try {
const targetUser = await interaction.client.users.fetch(
interaction.targetId,
{ force: true }
);
const avatarURL = targetUser.avatarURL({ size: 4096 });
if (!avatarURL) {
const errorEmbed = ErrorEmbed(
"Error",
`Could not retrieve ${targetUser}'s avatar`
);
if (interaction.deferred || interaction.replied) {
return await interaction.editReply({
embeds: [errorEmbed],
ephemeral: true,
});
} else {
return await interaction.reply({
embeds: [errorEmbed],
ephemeral: true,
});
}
}
const mediaEmbed = MediaEmbed(avatarURL);
await interaction.reply({ embeds: [mediaEmbed] });
} catch (error) {
const errorEmbed = ErrorEmbed(
"Error executing View User Avatar",
error.message
);
Error(`Error executing View User Avatar: ${error.message}`);
if (interaction.deferred || interaction.replied) {
await interaction.editReply({
embeds: [errorEmbed],
ephemeral: true,
});
} else {
await interaction.reply({
embeds: [errorEmbed],
ephemeral: true,
});
}
}
},
};
const { ContextMenuCommandBuilder, PermissionFlagsBits } = require("@discordjs/builders");
const { MediaEmbed, ErrorEmbed } = require("../utils/embeds");
const { Error, Debug } = require("../utils/logging");
module.exports = {
data: new ContextMenuCommandBuilder()
.setName("View User Avatar")
.setType(2)
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
try {
const targetUser = await interaction.client.users.fetch(
interaction.targetId,
{ force: true }
);
const avatarURL = targetUser.avatarURL({ size: 4096 });
if (!avatarURL) {
const errorEmbed = ErrorEmbed(
"Error",
`Could not retrieve ${targetUser}'s avatar`
);
if (interaction.deferred || interaction.replied) {
return await interaction.editReply({
embeds: [errorEmbed],
ephemeral: true,
});
} else {
return await interaction.reply({
embeds: [errorEmbed],
ephemeral: true,
});
}
}
const mediaEmbed = MediaEmbed(avatarURL);
await interaction.reply({ embeds: [mediaEmbed] });
} catch (error) {
const errorEmbed = ErrorEmbed(
"Error executing View User Avatar",
error.message
);
Error(`Error executing View User Avatar: ${error.message}`);
if (interaction.deferred || interaction.replied) {
await interaction.editReply({
embeds: [errorEmbed],
ephemeral: true,
});
} else {
await interaction.reply({
embeds: [errorEmbed],
ephemeral: true,
});
}
}
},
};
7 replies