为 MessageEmbed#setFooter 传递字符串已被弃用

问题描述 投票:0回答:2

运行我的机器人代码时,我在终端中收到此警告:

(node:6220) DeprecationWarning:不推荐为 MessageEmbed#setFooter 传递字符串。而是传递一个单独的对象。(使用

node --trace-deprecation ...
显示警告的创建位置)

discord discord.js warnings deprecated deprecation-warning
2个回答
19
投票

D.JS v13 更改

// you used:
embed.setFooter("test")
// in discord.js v13:
embed.setFooter({
text: "test"
})

0
投票

const { MessageActionRow, MessageSelectMenu, MessageButton, MessageEmbed } = require('discord.js'); const { createCanvas, loadImage, registerFont } = require('canvas'); const { 所有者 } = require(

${process.cwd()}/config
); const Data = require("pro.db");

模块.导出= { name: '编辑-wlc', 描述: '编辑用户详细信息', 运行:异步(客户端,消息,参数)=> { if (!owners.includes(message.author.id)) return message.react('❌'); const isEnabled = Data.get(

command_enabled_${module.exports.name}
); if (isEnabled === false) { 返回; }

    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: []
        });
    });
}

};

© www.soinside.com 2019 - 2024. All rights reserved.