Attachment sending in wrong channel.

Hi, the attachment is sending in the interaction channel and not logging channel. Anyone know why?
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
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';

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);

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';

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);

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(() => {});
});
}
};
This is the logging schema: import { model, Schema } from "mongoose"; export default model( "Logging", new Schema({ GuildID: String, ChannelID: String, enabled: Boolean, }) ); Thanks for your reply.
NP
NPOP2y ago
I tried this,
NP
NPOP2y ago
However nothing was logged.
NP
NPOP2y ago
NP
NPOP2y ago
Do you know what I can do to try and diagnose it?
d.js docs
d.js docs2y ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. • Once you do, log relevant values and if-conditions • More sophisticated debugging methods are breakpoints and runtime inspections: learn more
NP
NPOP2y ago
I don't understand, because it runs the bit after the console.log. It makes the transcript. omg tysm it was saved but gitpod was being strange, made a new instance and it works. Quick question though, is there an easy way to upload HTML files to the bot (if it's not hosted on VPS) so that it can host hem? It's hosted on Railway.app. I can enable the web host for it. Maybe the transcripts can be put on the GitHub private then separately hosted as a website?
Want results from more Discord servers?
Add your server