file being sent with content object object

Hi, the transcript file from here is being sent to GitHub with the contents of the file as [object Object] GitHub Integration:
import { Octokit } from "@octokit/rest";
import fs from "fs";

const octokit = new Octokit({ auth: "go3df8KI2dcd89" });

const owner = "repo";
const repo = "transcripts";
const branch = "main";

const createFileInRepo = async (
filePath: string,
content: string,
commitMessage: string,
) => {
try {
// Get the SHA of the latest commit
const { data: refData } = await octokit.git.getRef({
owner,
repo,
ref: `heads/${branch}`,
});
const sha = refData.object.sha;

// Get the latest commit
const { data: commitData } = await octokit.git.getCommit({
owner,
repo,
commit_sha: sha,
});

// Create a new tree with the new file
const { data: treeData } = await octokit.git.createTree({
owner,
repo,
base_tree: commitData.tree.sha,
tree: [
{
path: filePath,
mode: "100644",
content: content,
},
],
});

// Create a new commit with the new tree
const { data: commit } = await octokit.git.createCommit({
owner,
repo,
message: commitMessage,
tree: treeData.sha,
parents: [sha],
});

// Update the branch reference to point to the new commit
await octokit.git.updateRef({
owner,
repo,
ref: `heads/${branch}`,
sha: commit.sha,
});

console.log(`File ${filePath} created in repository ${owner}/${repo}`);
} catch (error) {
console.error(`Error creating file in repository: ${error}`);
}
};

export default createFileInRepo;
import { Octokit } from "@octokit/rest";
import fs from "fs";

const octokit = new Octokit({ auth: "go3df8KI2dcd89" });

const owner = "repo";
const repo = "transcripts";
const branch = "main";

const createFileInRepo = async (
filePath: string,
content: string,
commitMessage: string,
) => {
try {
// Get the SHA of the latest commit
const { data: refData } = await octokit.git.getRef({
owner,
repo,
ref: `heads/${branch}`,
});
const sha = refData.object.sha;

// Get the latest commit
const { data: commitData } = await octokit.git.getCommit({
owner,
repo,
commit_sha: sha,
});

// Create a new tree with the new file
const { data: treeData } = await octokit.git.createTree({
owner,
repo,
base_tree: commitData.tree.sha,
tree: [
{
path: filePath,
mode: "100644",
content: content,
},
],
});

// Create a new commit with the new tree
const { data: commit } = await octokit.git.createCommit({
owner,
repo,
message: commitMessage,
tree: treeData.sha,
parents: [sha],
});

// Update the branch reference to point to the new commit
await octokit.git.updateRef({
owner,
repo,
ref: `heads/${branch}`,
sha: commit.sha,
});

console.log(`File ${filePath} created in repository ${owner}/${repo}`);
} catch (error) {
console.error(`Error creating file in repository: ${error}`);
}
};

export default createFileInRepo;
8 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
NP
NPOP2y ago
Here's where the file is created.
import { ButtonInteraction, EmbedBuilder, TextChannel } from "discord.js";
import confirm from "../../Modules/Confirm";
import Thread from "../../Schemas/ThreadSchema";
import LoggingSchema from "../../Schemas/LoggingSchema";
import discordTranscripts from 'discord-html-transcripts';
import createFileInRepo from "./CreateFileInRepo";

export default async (interaction: ButtonInteraction) => {
interaction.deferUpdate();

const confirmation = await confirm(
interaction,
new EmbedBuilder()
.setTitle("Pending Confirmation")
.setColor("Blurple")
.setDescription(`Are you sure you want to close this thread?`)
.setFooter({ text: "You have 60 seconds." })
);

if (confirmation?.proceed) {
const thread = await Thread.findOne({ ChannelID: `${interaction.guild.id}-${interaction.channel.id}` });
if (!thread)
return interaction
.reply(
"We couldn't find the database model for this thread. Please delete the channel manually."
)
.catch(() => {
interaction.channel
.send(
"We couldn't find the database model for this thread. Please delete the channel manually."
)
.catch(() => {});
});

const loggingSchema = await LoggingSchema.findOne({ GuildID: interaction.guild.id });
const loggingChannel = interaction.guild.channels.cache.get(loggingSchema?.ChannelID) as TextChannel;

const attachment = await discordTranscripts.createTranscript(interaction.channel);

const fileName = `${interaction.channel.id}.html`;
const commitMessage = `Add transcript for thread ${interaction.channel.id}`;

await createFileInRepo(fileName, attachment.toString(), commitMessage);

loggingChannel.send({
content: `Transcript of the closed thread <#${interaction.channel.id}>:`,
files: [attachment],
});

interaction
.reply({
content: "Closing contact thread in **5 seconds!**",
embeds: [],
components: [],
})
.catch(() => {
interaction.channel
.send("Closing contact thread in **5 seconds!**")
.catch(() => {});
});
setTimeout(() => {
interaction.channel.delete().catch(() => {
interaction.channel
.send("I was unable to delete the channel.")
.catch(() => {});
});
thread.delete();
}, 5000);
} else {
interaction
.reply({
content: "Cancelling thread close operation.",
ephemeral: true,
})
.catch(() => {
interaction.channel
.send("Cancelling thread close operation.")
.catch(() => {});
});
}
};
import { ButtonInteraction, EmbedBuilder, TextChannel } from "discord.js";
import confirm from "../../Modules/Confirm";
import Thread from "../../Schemas/ThreadSchema";
import LoggingSchema from "../../Schemas/LoggingSchema";
import discordTranscripts from 'discord-html-transcripts';
import createFileInRepo from "./CreateFileInRepo";

export default async (interaction: ButtonInteraction) => {
interaction.deferUpdate();

const confirmation = await confirm(
interaction,
new EmbedBuilder()
.setTitle("Pending Confirmation")
.setColor("Blurple")
.setDescription(`Are you sure you want to close this thread?`)
.setFooter({ text: "You have 60 seconds." })
);

if (confirmation?.proceed) {
const thread = await Thread.findOne({ ChannelID: `${interaction.guild.id}-${interaction.channel.id}` });
if (!thread)
return interaction
.reply(
"We couldn't find the database model for this thread. Please delete the channel manually."
)
.catch(() => {
interaction.channel
.send(
"We couldn't find the database model for this thread. Please delete the channel manually."
)
.catch(() => {});
});

const loggingSchema = await LoggingSchema.findOne({ GuildID: interaction.guild.id });
const loggingChannel = interaction.guild.channels.cache.get(loggingSchema?.ChannelID) as TextChannel;

const attachment = await discordTranscripts.createTranscript(interaction.channel);

const fileName = `${interaction.channel.id}.html`;
const commitMessage = `Add transcript for thread ${interaction.channel.id}`;

await createFileInRepo(fileName, attachment.toString(), commitMessage);

loggingChannel.send({
content: `Transcript of the closed thread <#${interaction.channel.id}>:`,
files: [attachment],
});

interaction
.reply({
content: "Closing contact thread in **5 seconds!**",
embeds: [],
components: [],
})
.catch(() => {
interaction.channel
.send("Closing contact thread in **5 seconds!**")
.catch(() => {});
});
setTimeout(() => {
interaction.channel.delete().catch(() => {
interaction.channel
.send("I was unable to delete the channel.")
.catch(() => {});
});
thread.delete();
}, 5000);
} else {
interaction
.reply({
content: "Cancelling thread close operation.",
ephemeral: true,
})
.catch(() => {
interaction.channel
.send("Cancelling thread close operation.")
.catch(() => {});
});
}
};
Syjalo
Syjalo2y ago
discord-html-transcripts is not our library
NP
NPOP2y ago
I know, that works fine. It's an issue with getting the file transferred.
Syjalo
Syjalo2y ago
I suppose it returns an AttachmentBuilder which doesn't have .toString() method overridden. You need to use its attachment property.
NP
NPOP2y ago
Sorry, can you explain what you mean by this please? It's a html file @qjuh Can you support me here?
d.js docs
d.js docs2y ago
Documentation suggestion for @itsnp:property AttachmentBuilder#attachment The file associated with this attachment.
Syjalo
Syjalo2y ago
#rules 6
Want results from more Discord servers?
Add your server