- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
#I don't have text in my canvas
3 messages · Page 1 of 1 (latest)
const { SlashCommandBuilder } = require('discord.js');
const { createCanvas, loadImage } = require('@napi-rs/canvas');
const { AttachmentBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('version')
.setDescription('Sprawdź najnowszą wersję'),
async execute(interaction) {
// Utwórz kanwę
const canvas = createCanvas(700, 250);
const context = canvas.getContext('2d');
// Załaduj obraz tła
const background = await loadImage(
'https://cdn.discordapp.com/attachments/1166065898369589261/1180279071108767835/slownictwo_zimowe_po_angielsku_blogT-740x416.jpg?ex=657cd78b&is=656a628b&hm=e3e7068f17d8826a52a19b00418b56917ea9afc23ed7d1f6b7a8b47291fb0542&'
);
context.drawImage(background, 0, 0, canvas.width, canvas.height);
// Ustawienia tekstu
context.font = '60px sans-serif';
context.fillStyle = '#ffffff';
// Wpisz tekst
const text = 'Hello, Discord.js!';
context.fillText(text, canvas.width / 2.5, canvas.height / 1.8);
// Utwórz załącznik z bufora kanwy i wyślij odpowiedź
const buffer = canvas.toBuffer('image/png');
const attachment = new AttachmentBuilder(await canvas.encode('png'), { name: 'profile-image.png' });
interaction.reply({ files: [attachment] });
},
};