I'm trying to make my code only show a piece of text when the database is gives a certain value.
const canvas = Canvas.createCanvas(250, 250);
const ctx = canvas.getContext('2d');
ctx.fillStyle = message.content;
ctx.fillRect(0, 0, canvas.height, canvas.width)
db.get("label"+message.author.id).then(value => {
console.log(value)
if(value == 'on') {
console.log('true')
ctx.font = '40px Poppins';
ctx.fillStyle = '#ffffff';
ctx.strokeStyle = '#000000'
ctx.lineWidth = 1;
ctx.fillText(message.content, canvas.width/10, canvas.height / 2 + 20);
ctx.strokeText(message.content, canvas.width/10, canvas.height / 2 + 20);
}
})
This is what I have so far. Unfortunately, no matter the value in the database, it won't add the text. I've tested it without this stuff, and it adds the text. Can someone tell me how to fix this?
Edit: Here's my complete and total code for this problem:
if(message.content.startsWith('#') && message.content.length == 7) {
const canvas = Canvas.createCanvas(250, 250);
const ctx = canvas.getContext('2d');
ctx.fillStyle = message.content;
ctx.fillRect(0, 0, canvas.height, canvas.width)
db.get("label"+message.author.id).then(value => {
console.log(value)
if(value == 'on') {
console.log('true')
ctx.font = '40px Poppins';
ctx.fillStyle = '#ffffff';
ctx.strokeStyle = '#000000'
ctx.lineWidth = 1;
ctx.fillText(message.content, canvas.width/10, canvas.height / 2 + 20);
ctx.strokeText(message.content, canvas.width/10, canvas.height / 2 + 20);
}
})
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'color.png');
message.channel.send(attachment)
}