-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqr.js
More file actions
57 lines (52 loc) · 1.67 KB
/
Copy pathqr.js
File metadata and controls
57 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const QRCode = require('qrcode');
const { AttachmentBuilder, EmbedBuilder } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
name: 'qr',
data: new SlashCommandBuilder()
.setName('qr')
.setDescription('For generate a qr code')
.addStringOption((option) =>
option.setName('text').setDescription('Text to be generated into qr').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('resolution').setDescription('Image resolution in px (default is using 1024)').setRequired(false)
),
execute: (interaction) => {
const text = interaction.options.getString('text');
const resolution = interaction.options.getInteger('resolution') || 1024;
const path = 'images';
if (!fs.existsSync(path)) {
fs.mkdirSync(path);
}
const fileUrl = path + '/qrImage.png';
QRCode.toFile(
fileUrl,
text,
{
color: {
dark: '#000',
light: '#FFF',
},
width: resolution,
},
function (err) {
if (err) throw err;
const attachment = new AttachmentBuilder(fileUrl);
const qrImage = new EmbedBuilder()
.setColor('#4484f1')
.setTitle(`QR Code Generated!`)
.setImage('attachment://qrImage.png')
.setFooter({
text: `Command used by: ${interaction.user.tag}`,
iconURL: interaction.user.avatarURL(),
});
interaction.reply({ embeds: [qrImage], files: [attachment] }).then(() => {
console.log('Generated QR Code:', text);
fs.unlinkSync(fileUrl);
});
}
);
},
};