if (selectedOption === 'changeIcon') {
let iconEmbed = new MessageEmbed().setDescription('Please provide a new icon URL or emoji for the role within 1 minute.');
await interaction.reply({ embeds: [iconEmbed], ephemeral: true });
const iconFilter = response => response.author.id === message.author.id;
const collectedIcon = await interaction.channel.awaitMessages({ filter: iconFilter, max: 1, time: 60000 });
if (collectedIcon.size > 0) {
let newIcon = collectedIcon.first().content;
try {
// If it's an emoji, check if it's a valid emoji
if (newIcon.startsWith('<:') && newIcon.endsWith('>')) {
// Custom emoji
const emojiId = newIcon.match(/\d+/)[0];
newIcon = `https://cdn.discordapp.com/emojis/${emojiId}.png`;
} else if (/^https?:\/\/.+\.(jpg|jpeg|png|gif)$/i.test(newIcon)) {
// URL to an image
} else {
throw new Error('Invalid URL or emoji');
}
await role.setIcon(newIcon);
let successEmbed = new MessageEmbed().setDescription('Role icon changed successfully.');
await interaction.followUp({ embeds: [successEmbed], ephemeral: true });
} catch (error) {
let errorEmbed = new MessageEmbed().setDescription('Failed to change role icon. Ensure the URL is valid or the emoji is accessible.');
await interaction.followUp({ embeds: [errorEmbed], ephemeral: true });
}
} else {
let timeoutEmbed = new MessageEmbed().setDescription('Time expired. Role icon not changed.');
await interaction.followUp({ embeds: [timeoutEmbed], ephemeral: true });
}
}
if (selectedOption === 'changeIcon') {
let iconEmbed = new MessageEmbed().setDescription('Please provide a new icon URL or emoji for the role within 1 minute.');
await interaction.reply({ embeds: [iconEmbed], ephemeral: true });
const iconFilter = response => response.author.id === message.author.id;
const collectedIcon = await interaction.channel.awaitMessages({ filter: iconFilter, max: 1, time: 60000 });
if (collectedIcon.size > 0) {
let newIcon = collectedIcon.first().content;
try {
// If it's an emoji, check if it's a valid emoji
if (newIcon.startsWith('<:') && newIcon.endsWith('>')) {
// Custom emoji
const emojiId = newIcon.match(/\d+/)[0];
newIcon = `https://cdn.discordapp.com/emojis/${emojiId}.png`;
} else if (/^https?:\/\/.+\.(jpg|jpeg|png|gif)$/i.test(newIcon)) {
// URL to an image
} else {
throw new Error('Invalid URL or emoji');
}
await role.setIcon(newIcon);
let successEmbed = new MessageEmbed().setDescription('Role icon changed successfully.');
await interaction.followUp({ embeds: [successEmbed], ephemeral: true });
} catch (error) {
let errorEmbed = new MessageEmbed().setDescription('Failed to change role icon. Ensure the URL is valid or the emoji is accessible.');
await interaction.followUp({ embeds: [errorEmbed], ephemeral: true });
}
} else {
let timeoutEmbed = new MessageEmbed().setDescription('Time expired. Role icon not changed.');
await interaction.followUp({ embeds: [timeoutEmbed], ephemeral: true });
}
}