hiarcs
hiarcs
DIAdiscord.js - Imagine an app
Created by hiarcs on 10/9/2024 in #djs-questions
TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream.
my bot has been running fine in production for years but today i'm getting this message on startup with no changes of any kind:
/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:2046
fetchParams.controller.controller.error(new TypeError('terminated', {
^

TypeError: terminated
at Fetch.onAborted (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:2046:49)
at Fetch.emit (node:events:513:28)
at Fetch.terminate (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:93:10)
at /home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:511:30
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of ReadableStream
at new NodeError (node:internal/errors:393:5)
at eos (node:internal/streams/end-of-stream:65:11)
at fetchFinale (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:1101:5)
at mainFetch (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:765:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
}
/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:2046
fetchParams.controller.controller.error(new TypeError('terminated', {
^

TypeError: terminated
at Fetch.onAborted (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:2046:49)
at Fetch.emit (node:events:513:28)
at Fetch.terminate (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:93:10)
at /home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:511:30
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of Stream. Received an instance of ReadableStream
at new NodeError (node:internal/errors:393:5)
at eos (node:internal/streams/end-of-stream:65:11)
at fetchFinale (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:1101:5)
at mainFetch (/home/ubuntu/dice-witch/node_modules/undici/lib/web/fetch/index.js:765:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
}
i'm using bun and djs 14.16.3
3 replies
DIAdiscord.js - Imagine an app
Created by hiarcs on 10/22/2022 in #djs-questions
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);
};
4 replies