so I have a Discord Bot and I wanted to create a memberInfo slashcommand. So I made this code for it:
const { ChatInputCommandInteraction, SlashCommandBuilder, EmbedBuilder, AttachmentBuilder } = require("discord.js");
const { profileImage } = require("discord-arts");
module.exports = {
data: new SlashCommandBuilder()
.setName("memberinfo")
.setDescription("View your or any member's information.")
.setDMPermission(false)
.addUserOption((option) => option
.setName("member")
.setDescription("View a member's information. Leave empty to view your own")
),
/**
* @param {ChatInputCommandInteraction} interaction
*/
async execute(interaction) {
await interaction.deferReply()
const member = interaction.options.getMember("member") || interaction.member;
if(member.user.bot) return await interaction.editReply({
embeds:
[
new EmbedBuilder()
.setDescription("At the moment, bots are not supported for this command.")
],
ephemeral: true
});
try {
const fetchedMembers = await interaction.guild.members.fetch();
const profileBuffer = await profileImage(member.id);
const imageAttachment = new AttachmentBuilder(profileBuffer,
{name: 'profile.png'});
const joinPosition = Array.from(fetchedMembers
.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp)
.keys())
.indexOf(member.id) + 1;
const topRoles = member.roles.cache
.sort((a, b) => b.position - a.position)
.map(role => role);
const userBadges = member.user.flags.toArray()
const joinTime = parseInt(member.joinedTimestamp / 1000);
const createdTime = parseInt(member.createdTimestamp / 1000);
const Booster = member.premiumSince ? "<:discordboost7:1086751631221211247>" : "❌";
const Embed = new EmbedBuilder()
.setAuthor({name: `${member.user.tag} | General Information`, iconURL: member.displayAvatarURL()})
.setColor(member.displayColor)
.setDescription(`On <t:${joinTime}:D>, ${member.user.username} joined as the **${addSuffix(joinPosition)}** member of this guild.`)
.setImage("attachment://profile.png")
.addFields([
{name: "Badges", value: `${addBadges(userBadges).join("")}`, inline: true},
{name: "Booster", value: `${Booster}`, inline: true},
{name: "Top Roles", value: `${topRoles.join("")}`, inline: false},
{name: "Created", value: `<t:${createdTime}:R>`, inline: true},
{name: "Joined", value: `<t:${joinTime}:R>`, inline: true},
{name: "Identifier", value: `${member.id}`, inline: false},
{name: "Avatar", value: `[Link](${member.displayAvatarURL()})`, inline: true},
{name: "Banner", value: `[Link](${(await member.user.fetch()).bannerURL})`, inline: true},
]);
await interaction.editReply({embeds: [Embed], files: {imageAttachment}});
} catch (error) {
await interaction.editReply({content: "An error occured: Contact the Developer (MrAplex#9627)"});
throw error;
}
}
}
function addSuffix(number) {
if(number % 100 >= 11 && number % 100 <= 13)
return number + "th";
switch(number % 10) {
case 1: return number + "st";
case 2: return number + "nd";
case 3: return number + "rd";
}
return number + "th";
}
function addBadges(badgeNames) {
if(!badgeNames.length) return ["X"];
const badgeMap = {
"ActiveDeveloper": "<:activedeveloper:1086751628423606383>",
"BugHunterLevel1": "<:discordbughunter1:1086751635860115476>",
"BugHunterLevel2": "<:discordbughunter2:1086751637416181821>",
"PremiumEarlySupporter": "<:discordearlysupporter:1086751640410923028>",
"Partner": "<:discordpartner:1086751645712535723>",
"Staff": "<:discordmod:1086751641887314013>",
"HypeSquadOnlineHouse1": "<:hypesquadbravery:1086751651479687199>", // bravery
"HypeSquadOnlineHouse2": "<:hypesquadbrilliance:1086751653585244202>", // brilliance
"HypeSquadOnlineHouse3": "<:hypesquadbalance:1086751649810370652>", // balance
"Hypesquad": "<:hypesquadevents:1086751902542331975>",
"CertifiedModerator": "<:discordmod:1086751641887314013>",
"VerifiedDeveloper": "<:discordbotdev:1086751632903131306>",
};
return badgeNames.map(badgeName => badgeMap[badgeName] || '❔');
}
My problem here is that when I type use the slashcommand in Discord, I get an error in Terminal saying the following:
/Users/Aplex/Documents/Royal Bot/node_modules/discord.js/src/structures/MessagePayload.js:187
const attachments = this.options.files?.map((file, index) => ({
^
TypeError: this.options.files?.map is not a function
at MessagePayload.resolveBody (/Users/Aplex/Documents/Royal Bot/node_modules/discord.js/src/structures/MessagePayload.js:187:45)
at InteractionWebhook.editMessage (/Users/Aplex/Documents/Royal Bot/node_modules/discord.js/src/structures/Webhook.js:336:50)
at ChatInputCommandInteraction.editReply (/Users/Aplex/Documents/Royal Bot/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:158:36)
at Object.execute (/Users/Aplex/Documents/Royal Bot/Commands/Public/memberInfo.js:69:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
How do I fix this? I have no Idea what to do. I am guessing the problem is when I typed in code this (inside the try-catch):
await interaction.editReply({embeds: [Embed], files:{imageAttachment}});