Passing strings for MessageEmbed#setFooter is deprecated
Asked Answered
F

2

8

I'm getting this warning in the terminal when running my bot code:

(node:6220) DeprecationWarning: Passing strings for MessageEmbed#setFooter is deprecated. Pass a sole object instead.(Use node --trace-deprecation ... to show where the warning was created)

Fink answered 6/1, 2022 at 3:59 Comment(2)
Please provide enough code so others can better understand or reproduce the problem.Parry
You can ignore this message, it doesn't make any problem to the code, it's still working perfectly fineLucielucien
G
19

D.JS v13 changes

// you used:
embed.setFooter("test")
// in discord.js v13:
embed.setFooter({
text: "test"
})
Ghoul answered 19/1, 2022 at 23:7 Comment(0)
F
0

const { MessageActionRow, MessageSelectMenu, MessageButton, MessageEmbed } = require('discord.js'); const { createCanvas, loadImage, registerFont } = require('canvas'); const { owners } = require(${process.cwd()}/config); const Data = require("pro.db");

module.exports = { name: 'edit-wlc', description: 'Edit user details', run: async (client, message, args) => { if (!owners.includes(message.author.id)) return message.react('❌'); const isEnabled = Data.get(command_enabled_${module.exports.name}); if (isEnabled === false) { return; }

    registerFont(`./Fonts/Cairo-Regular.ttf`, { family: 'Cairo' });

    const initialMenu = new MessageSelectMenu()
        .setCustomId('edit_select')
        .setPlaceholder('اختر ما تريد تحريره')
        .addOptions([
            { label: 'إحديثات الاسم', value: 'username', emoji: '1216751616171184269' }, 
            { label: 'إحديثات الافتار', value: 'avatar', emoji: '1216751616171184269' },
            { label: 'صورة الولكم', value: 'image', emoji: '1216751616171184269' },
            { label: 'شات الولكم', value: 'channel', emoji: '1216751616171184269' },
            { label: 'رسالة الولكم', value: 'messg', emoji: '1216751616171184269' }
        ]);

    const deleteButton = new MessageButton()
        .setCustomId('Cancele')
        .setLabel('إلغاء')
        .setStyle('DANGER');

    const Cancele = new MessageActionRow().addComponents(deleteButton);
    
    const initialMenuRow = new MessageActionRow().addComponents(initialMenu);

    const embed = new MessageEmbed()
        .setTitle('**يرجى تحديد نوع التعديل**')
        .setFooter({ text: 'Footer Text', iconURL: 'URL' })
        .setAuthor({ name: 'Author Name', iconURL: 'URL' });

    await message.reply({
        embeds: [embed],
        components: [initialMenuRow, Cancele]
    });

    // إنشاء جمع البيانات للتفاعل مع القائمة
    const filter = (interaction) => interaction.user.id === message.author.id && interaction.isSelectMenu();
    const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 });
    // الاستماع لتحديد القائمة
    collector.on('collect', async (interaction) => {
        if (interaction.user.id !== message.author.id) return; 
        let selectedOption;
        if (!interaction.optionUsed) {
            selectedOption = interaction.values[0];
            interaction.optionUsed = true;
        }
        // معالجة تحرير اسم المستخدم
        if (selectedOption === 'username') {
            await interaction.message.delete();
            if (message.author.bot) return;
    
            const canvas = createCanvas(826, 427);
            const ctx = canvas.getContext('2d');
    
            // Initial position of username
            let x = canvas.width / 2;
            let y = canvas.height / 2;
    
            // Initial font size
            let fontSize = 40;
    
            const username = message.author.displayName;
    
            // Load background image URL
            const backgroundImageURL = Data.get(`imgwlc_${message.guild.id}`);
    
            // Load background image if URL is provided
            let backgroundImage;
            if (backgroundImageURL) {
                backgroundImage = await loadImage(backgroundImageURL);
                canvas.width = backgroundImage.width; // Set canvas width to background image width
                canvas.height = backgroundImage.height; // Set canvas height to background image height
    
                // Draw background image
                ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
            } else {
                // Draw transparent background
                ctx.fillStyle = 'rgba(0, 0, 0, 0)';
                ctx.fillRect(0, 0, canvas.width, canvas.height);
            }
    
            // Draw user's avatar with specified settings
            const userAvatarURL = message.author.displayAvatarURL({ format: 'png', size: 1024 });
            const avatar = await loadImage(userAvatarURL);
            const avatarUpdates = Data.get(`editwel_${message.guild.id}`) || { size: 260, x: 233, y: 83.5, isCircular: true };
            const { size, x: avatarX, y: avatarY, isCircular } = avatarUpdates;
            ctx.save();
            if (isCircular) {
                ctx.beginPath();
                ctx.arc(avatarX + size / 2, avatarY + size / 2, size / 2, 0, Math.PI * 2);
                ctx.closePath();
                ctx.clip();
            }
            ctx.drawImage(avatar, avatarX, avatarY, size, size);
            ctx.restore();
    
            // Draw username on canvas
            ctx.font = `${fontSize}px Cairo`; // Change 'Your Font Name' to your font family
            ctx.fillStyle = '#FFFFFF'; // Change color as needed
            ctx.fillText(username, x, y); // Draw username at current position
    
            // Create buttons
            const moveUpButton = new MessageButton()
                .setCustomId('up')
                .setEmoji("⬆️")
                .setStyle('PRIMARY');
    
            const moveDownButton = new MessageButton()
                .setCustomId('down')
                .setEmoji("⬇️")
                .setStyle('PRIMARY');
    
            const moveLeftButton = new MessageButton()
                .setCustomId('left')
                .setEmoji("⬅️")
                .setStyle('PRIMARY');
    
            const moveRightButton = new MessageButton()
                .setCustomId('right')
                .setEmoji("➡️")
                .setStyle('PRIMARY');
    
            const increaseSizeButton = new MessageButton()
                .setCustomId('increase')
                .setEmoji("➕")
                .setStyle('SUCCESS');
    
            const decreaseSizeButton = new MessageButton()
                .setCustomId('decrease')
                .setEmoji("➖")
                .setStyle('DANGER');
    
            const saveButton = new MessageButton()
                .setCustomId('save')
                .setEmoji("✅")
                .setStyle('SUCCESS');
    
            const cancelButton = new MessageButton()
                .setCustomId('cancel')
                .setEmoji("❌")
                .setStyle('DANGER');
    
            const row = new MessageActionRow()
                .addComponents(moveUpButton, moveLeftButton, saveButton, cancelButton, moveRightButton, moveDownButton, increaseSizeButton, decreaseSizeButton);
    
            // Send the canvas with buttons to the channel
            const welcomewlcchannel = Data.get(`welcomewlcchannel_${message.guild.id}`);
            const channel = message.guild.channels.cache.get(welcomewlcchannel);
            if (!channel) return message.reply('هذا الشات غير موجود, الرجاء استخدام الأمر بشكل صحيح.');
            channel.send({
                content: `يرجى التحريك وتحديث موقع الاسم`,
                files: [canvas.toBuffer()],
                components: [row]
            }).then((msg) => {
                // Add reaction collector to listen for button clicks
                const filter = (interaction) => {
                    return interaction.message.id === msg.id && interaction.user.id === message.author.id;
                };
                const collector = channel.createMessageComponentCollector({
                    filter,
                    time: 60000
                });
                collector.on('collect', async (interaction) => {
                    const { customId } = interaction;
                    if (customId === 'up') {
                        y -= 10;
                    } else if (customId === 'down') {
                        y += 10;
                    } else if (customId === 'left') {
                        x -= 10;
                    } else if (customId === 'right') {
                        x += 10;
                    } else if (customId === 'increase') {
                        fontSize += 5;
                        ctx.font = `${fontSize}px Cairo`;
                    } else if (customId === 'decrease') {
                        fontSize -= 5;
                        ctx.font = `${fontSize}px Cairo`;
                    } else if (customId === 'save') {
                        Data.set(`editwel_${message.guild.id}`, { size, x: avatarX, y: avatarY });
                        msg.delete();
                        interaction.deferUpdate();
                        return;
                    } else if (customId === 'cancel') {
                        msg.delete();
                        interaction.deferUpdate();
                        return;
                    }
                    // Clear the canvas
                    ctx.clearRect(0, 0, canvas.width, canvas.height);
                    // Redraw the canvas with updated position and font size
                    if (backgroundImageURL) {
                        ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);
                    } else {
                        ctx.fillStyle = 'rgba(0, 0, 0, 0)';
                        ctx.fillRect(0, 0, canvas.width, canvas.height);
                    }
                    ctx.save();
                    if (isCircular) {
                        ctx.beginPath();
                        ctx.arc(avatarX + size / 2, avatarY + size / 2, size / 2, 0, Math.PI * 2);
                        ctx.closePath();
                        ctx.clip();
                    }
                    ctx.drawImage(avatar, avatarX, avatarY, size, size);
                    ctx.restore();
                    ctx.font = `${fontSize}px Cairo`;
                    ctx.fillStyle = '#FFFFFF';
                    ctx.fillText(username, x, y);
                    // Send the updated canvas back to the channel
                    channel.send({
                        content: `يرجى التحريك وتحديث موقع الاسم`,
                        files: [canvas.toBuffer()],
                        components: [row]
                    });
                    interaction.deferUpdate();
                });
                collector.on('end', () => {
                    // Remove all buttons when the collector ends
                    msg.edit({
                        components: []
                    });
                });
            }).catch(console.error);
        }
    });
    collector.on('end', () => {
        // Remove the initial menu when the collector ends
        message.edit({
            components: []
        });
    });
}

};

Furlani answered 6/6, 2024 at 0:34 Comment(1)
Keeping in mind that Cactusdev was able to advance a solution in two lines (old line that attracts warning and new line that doesn't), this looks like a lot more code than is necessary to solve the warning and no explanation as to how it answers the question.Skycap

© 2022 - 2025 — McMap. All rights reserved.