Created
February 6, 2021 14:44
-
-
Save LiamTownsley/fb20d404a3451b667fbfddd9298fafc1 to your computer and use it in GitHub Desktop.
For assistance on https://stackoverflow.com/questions/66071010/how-do-you-send-a-base64-image-to-discord-webhook/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Discord = require('discord.js'); | |
const bot = new Discord.Client(); | |
bot.on('message', async msg => { | |
if(msg.author.bot) return; | |
if(msg.content === '!test') { | |
const Hook = new Discord.WebhookClient("WEBHOOK_ID", "WEBHOOK_TOKEN"); | |
const image = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/.........' | |
const imageStream = new Buffer.from(image.split("base64,")[1],'base64'); | |
const attachment = new Discord.MessageAttachment(imageStream); | |
const embed = new Discord.MessageEmbed().attachFiles(attachment); | |
Hook.send(embed); | |
} | |
}); | |
bot.login('DISCORD_TOKEN'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment