How to create an attachment without using AttachmentBuilder?
i'm trying to attach an image inside of a
broadcastEval
. i have the image converted into a dataURI string, and i'm rebuilding it in the broadcastEval
using Buffer.from
. but i'm not aware of any way to create the attachment with calling new AttachmentBuilder
, which doesn't work in broadcastEval
.
here's my code:
const logEvent = (
c: Client,
{
embed,
logOutputChannelID,
canvasString,
}: {
embed: any;
logOutputChannelID?: string;
canvasString?: string;
}
) => {
console.log("logEvent ran");
if (!logOutputChannelID) return;
const logOutputChannel = c.channels.cache.get(
logOutputChannelID
) as TextChannel;
if (logOutputChannel) {
if (canvasString) {
const attachment = new AttachmentBuilder(
Buffer.from(canvasString.split(",")[1], "base64"),
{ name: "currentDice.png" }
);
logOutputChannel.send({
embeds: [
{
image: {
url: "attachment://currentDice.png",
},
},
],
files: [attachment],
});
} else {
logOutputChannel
.send({
embeds: [embed],
})
.catch((err: Error) => console.error(err));
}
}
};
console.log("shard", discord?.shard);
discord?.shard
?.broadcastEval(logEvent, {
context: {
embed: generateEmbed(),
logOutputChannelID,
canvasString,
},
})
// .then(console.log)
.catch(console.error);
};
const logEvent = (
c: Client,
{
embed,
logOutputChannelID,
canvasString,
}: {
embed: any;
logOutputChannelID?: string;
canvasString?: string;
}
) => {
console.log("logEvent ran");
if (!logOutputChannelID) return;
const logOutputChannel = c.channels.cache.get(
logOutputChannelID
) as TextChannel;
if (logOutputChannel) {
if (canvasString) {
const attachment = new AttachmentBuilder(
Buffer.from(canvasString.split(",")[1], "base64"),
{ name: "currentDice.png" }
);
logOutputChannel.send({
embeds: [
{
image: {
url: "attachment://currentDice.png",
},
},
],
files: [attachment],
});
} else {
logOutputChannel
.send({
embeds: [embed],
})
.catch((err: Error) => console.error(err));
}
}
};
console.log("shard", discord?.shard);
discord?.shard
?.broadcastEval(logEvent, {
context: {
embed: generateEmbed(),
logOutputChannelID,
canvasString,
},
})
// .then(console.log)
.catch(console.error);
};
2 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Error [ReferenceError]: discord_js_1 is not defined
at eval (eval at _eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12), <anonymous>:8:36)
at eval (eval at _eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12), <anonymous>:28:7)
at Client._eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12)
at ShardClientUtil._handleMessage (/home/christopher/Code/dice-witch/node_modules/discord.js/src/sharding/ShardClientUtil.js:195:82)
at process.emit (node:events:525:35)
at emit (node:internal/child_process:946:14)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
Error [ReferenceError]: discord_js_1 is not defined
at eval (eval at _eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12), <anonymous>:8:36)
at eval (eval at _eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12), <anonymous>:28:7)
at Client._eval (/home/christopher/Code/dice-witch/node_modules/discord.js/src/client/Client.js:470:12)
at ShardClientUtil._handleMessage (/home/christopher/Code/dice-witch/node_modules/discord.js/src/sharding/ShardClientUtil.js:195:82)
at process.emit (node:events:525:35)
at emit (node:internal/child_process:946:14)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
broadcastEval