JulianRJC
JulianRJC
DIAdiscord.js - Imagine an app
Created by JulianRJC on 9/11/2024 in #djs-questions
File Sending
const transcript = await createTranscript(interaction.channel, {
fileName: `transcript-${interaction.channel.name}.html`,
limit: -1,
returnType: 'attachment',
}).then(() => {
debug("Transcript opgeslagen")
})
const transcript = await createTranscript(interaction.channel, {
fileName: `transcript-${interaction.channel.name}.html`,
limit: -1,
returnType: 'attachment',
}).then(() => {
debug("Transcript opgeslagen")
})
This code gives this error when sending the file in a message:
C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:191
description: file.description,
^

TypeError: Cannot read properties of undefined (reading 'description')
at C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:191:25
at Array.map (<anonymous>)
at MessagePayload.resolveData (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:189:45)
at TextChannel.send (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:154:61)
at func_createTranscript (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\events\ticketButtons.js:40:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.4.0
C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:191
description: file.description,
^

TypeError: Cannot read properties of undefined (reading 'description')
at C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:191:25
at Array.map (<anonymous>)
at MessagePayload.resolveData (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\MessagePayload.js:189:45)
at TextChannel.send (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:154:61)
at func_createTranscript (C:\Users\Gebruiker\Desktop\Code\ticket-bot\Ticket-Bot-Cartel\events\ticketButtons.js:40:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.4.0
Message sending:
await transcriptChannel.send({embeds: [
new MessageEmbed()
.setAuthor({name: member.user.tag, iconURL: member.user.displayAvatarURL({dynamic: true})})
.addField("Ticket Owner", `<@${userData.ownerID}>`, true)
.addField("Ticket Name", interaction.channel.name, true)
.setColor("ORANGE")
], files: [transcript]}).then((msg) => {
msg.edit({embeds: [
msg.embeds[0]
.addField("Panel Name", `${userData.ticketPanel}`, true)
.addField("Direct Transcript", `[Direct Transcript](${msg.attachments.first().url})`, true)
.addField("Ticket Closed", interaction.user.tag, true)
.setColor("GREEN")
]});
});
await transcriptChannel.send({embeds: [
new MessageEmbed()
.setAuthor({name: member.user.tag, iconURL: member.user.displayAvatarURL({dynamic: true})})
.addField("Ticket Owner", `<@${userData.ownerID}>`, true)
.addField("Ticket Name", interaction.channel.name, true)
.setColor("ORANGE")
], files: [transcript]}).then((msg) => {
msg.edit({embeds: [
msg.embeds[0]
.addField("Panel Name", `${userData.ticketPanel}`, true)
.addField("Direct Transcript", `[Direct Transcript](${msg.attachments.first().url})`, true)
.addField("Ticket Closed", interaction.user.tag, true)
.setColor("GREEN")
]});
});
4 replies
DIAdiscord.js - Imagine an app
Created by JulianRJC on 8/18/2024 in #djs-questions
It doesnt set the permissons
I dont get an error https://pastebin.com/ccAVhUVw
4 replies
DIAdiscord.js - Imagine an app
Created by JulianRJC on 6/16/2024 in #djs-questions
Discord Login
I have a discord login with Express.js
app.get("/discord", async (req, res) => {
const code = req.query.code;
const params = new URLSearchParams();
params.append("client_id", process.env.LOGIN_CLIENT_ID);
params.append("client_secret", process.env.LOGIN_CLIENT_SECRET);
params.append("grant_type", "authorization_code");
params.append("code", code); // Ensure code is correctly being passed here
params.append("redirect_uri", "http://localhost:3001/discord");

console.log('Client ID:', process.env.LOGIN_CLIENT_ID);
console.log('Client Secret:', process.env.LOGIN_CLIENT_SECRET);
console.log('Code:', code);

try {
const response = await axios.post('https://discord.com/api/oauth2/token', params);
const { access_token, token_type } = response.data;
const userDataResponse = await axios.get("https://discord.com/api/users/@me", {
headers: {
Authorization: `${token_type} ${access_token}`
}
});
console.log(`Data: ${userDataResponse.data.access_token}`);

const user = {
discordid: userDataResponse.data.id,
name: userDataResponse.data.username,
discord: true,
acces_token: response.data.access_token
};
let guildid;
console.log(`username: ${userDataResponse.data.username}`);
console.log(`Email: ${userDataResponse.data.email}`);
if (userDataResponse.data.username === "julianrjc3") {
guildid = "1233925574070767696";
} else {
guildid = "1230258666146365481";
}
req.session.user = user;
req.session.guildid = guildid;
return res.redirect("/dashboard");
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
}
});
app.get("/discord", async (req, res) => {
const code = req.query.code;
const params = new URLSearchParams();
params.append("client_id", process.env.LOGIN_CLIENT_ID);
params.append("client_secret", process.env.LOGIN_CLIENT_SECRET);
params.append("grant_type", "authorization_code");
params.append("code", code); // Ensure code is correctly being passed here
params.append("redirect_uri", "http://localhost:3001/discord");

console.log('Client ID:', process.env.LOGIN_CLIENT_ID);
console.log('Client Secret:', process.env.LOGIN_CLIENT_SECRET);
console.log('Code:', code);

try {
const response = await axios.post('https://discord.com/api/oauth2/token', params);
const { access_token, token_type } = response.data;
const userDataResponse = await axios.get("https://discord.com/api/users/@me", {
headers: {
Authorization: `${token_type} ${access_token}`
}
});
console.log(`Data: ${userDataResponse.data.access_token}`);

const user = {
discordid: userDataResponse.data.id,
name: userDataResponse.data.username,
discord: true,
acces_token: response.data.access_token
};
let guildid;
console.log(`username: ${userDataResponse.data.username}`);
console.log(`Email: ${userDataResponse.data.email}`);
if (userDataResponse.data.username === "julianrjc3") {
guildid = "1233925574070767696";
} else {
guildid = "1230258666146365481";
}
req.session.user = user;
req.session.guildid = guildid;
return res.redirect("/dashboard");
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
}
});
But if i want to get the servers where the bot and the user is in and where the user can manage the guild: I get this error
5 replies