n4a
n4a
DIAdiscord.js - Imagine an app
Created by n4a on 2/9/2024 in #djs-questions
Unknown member
DiscordAPIError[10007]: Unknown Member Code:
if (subcommand === "zmień-prezesa") {
const channel_topic = interaction.channel.topic;

if (!channel_topic || channel_topic !== name) return interaction.reply({ content: "`[ ❌ ]` Ten kanał nie należy do podanego klubu!", ephemeral: true });

const club_data = database.get(`guilds.${name}`);
const old_owner = database.get(`users.${club_data.owner}`);
const new_owner = database.get(`users.${user.id}`);

if (!new_owner) {
database.set(`users.${user.id}`, {
club: "",
club_role: "",
pass_block: new Date().getTime(),
balance: 0,
});

return interaction.reply({ content: "`[ ✔️ ]` Pomyślnie utworzono konto użytkownika <@" + user.id + ">, użyj komendy ponownie!", ephemeral: true });
}

if (new_owner.club !== name) return interaction.reply({ content: "`[ ❌ ]` Podany użytkownik jest w innym klubie!", ephemeral: true });

if (!club_data) return interaction.reply({ content: "`[ ❌ ]` Nie znaleziono klubu!", ephemeral: true });

const m_guild = await interaction.client.guilds.cache.get(main_guild_id);
const c_guild = await interaction.client.guilds.cache.get(interaction.guild.id);

if (!m_guild || !c_guild) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć serwera discord!", ephemeral: true });

const m_old_member = await m_guild.members.fetch(club_data.owner);
const c_old_member = await c_guild.members.fetch(club_data.owner);
const m_new_member = await m_guild.members.fetch(user.id);
const c_new_member = await c_guild.members.fetch(user.id);

if (!m_old_member || !c_old_member || !m_new_member || !c_new_member) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć użytkownika!", ephemeral: true });

const m_rank_role = await m_guild.roles.cache.find(r => r.name === "• Zarząd Klubu | IFL");
const c_rank_role = await c_guild.roles.cache.find(r => r.name === "✬ Prezes Klubu | IFL");
const m_role = await m_guild.roles.cache.find(role => role.name === "• " + name + " | Kluby");
const c_role = await c_guild.roles.cache.find(role => role.name === name + " | Kluby");

if (!m_role || !c_role || !m_rank_role || !c_rank_role) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć roli!", ephemeral: true });

await m_old_member.roles.remove(m_rank_role);
await c_old_member.roles.remove(c_rank_role);
await m_old_member.roles.remove(m_role);
await c_old_member.roles.remove(c_role);
await m_new_member.roles.add(m_rank_role);
await c_new_member.roles.add(c_rank_role);
await m_new_member.roles.add(m_role);
await c_new_member.roles.add(c_role);

const uu3 = await interaction.guild.members.fetch(club_data.owner);

let m_table = database.get(`guilds.${name}.members`);
m_table = m_table.filter(value => value !== uu3.user.username);

database.set(`guilds.${name}.members`, m_table);
database.push(`guilds.${name}.members`, user.username);

database.set(`guilds.${name}.owner`, user.id);
database.set(`users.${user.id}.club`, old_owner.club);
database.set(`users.${user.id}.club_role`, old_owner.club_role);
database.set(`users.${club_data.owner}.club`, "");
database.set(`users.${club_data.owner}.club_role`, "");

interaction.reply({ content: "`[ ✔️ ]` Pomyślnie zmieniłeś prezesa klubu **" + name + "** na <@" + user.id + ">!", ephemeral: true });
}
if (subcommand === "zmień-prezesa") {
const channel_topic = interaction.channel.topic;

if (!channel_topic || channel_topic !== name) return interaction.reply({ content: "`[ ❌ ]` Ten kanał nie należy do podanego klubu!", ephemeral: true });

const club_data = database.get(`guilds.${name}`);
const old_owner = database.get(`users.${club_data.owner}`);
const new_owner = database.get(`users.${user.id}`);

if (!new_owner) {
database.set(`users.${user.id}`, {
club: "",
club_role: "",
pass_block: new Date().getTime(),
balance: 0,
});

return interaction.reply({ content: "`[ ✔️ ]` Pomyślnie utworzono konto użytkownika <@" + user.id + ">, użyj komendy ponownie!", ephemeral: true });
}

if (new_owner.club !== name) return interaction.reply({ content: "`[ ❌ ]` Podany użytkownik jest w innym klubie!", ephemeral: true });

if (!club_data) return interaction.reply({ content: "`[ ❌ ]` Nie znaleziono klubu!", ephemeral: true });

const m_guild = await interaction.client.guilds.cache.get(main_guild_id);
const c_guild = await interaction.client.guilds.cache.get(interaction.guild.id);

if (!m_guild || !c_guild) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć serwera discord!", ephemeral: true });

const m_old_member = await m_guild.members.fetch(club_data.owner);
const c_old_member = await c_guild.members.fetch(club_data.owner);
const m_new_member = await m_guild.members.fetch(user.id);
const c_new_member = await c_guild.members.fetch(user.id);

if (!m_old_member || !c_old_member || !m_new_member || !c_new_member) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć użytkownika!", ephemeral: true });

const m_rank_role = await m_guild.roles.cache.find(r => r.name === "• Zarząd Klubu | IFL");
const c_rank_role = await c_guild.roles.cache.find(r => r.name === "✬ Prezes Klubu | IFL");
const m_role = await m_guild.roles.cache.find(role => role.name === "• " + name + " | Kluby");
const c_role = await c_guild.roles.cache.find(role => role.name === name + " | Kluby");

if (!m_role || !c_role || !m_rank_role || !c_rank_role) return interaction.reply({ content: "`[ ❌ ]` Nie udało się znaleźć roli!", ephemeral: true });

await m_old_member.roles.remove(m_rank_role);
await c_old_member.roles.remove(c_rank_role);
await m_old_member.roles.remove(m_role);
await c_old_member.roles.remove(c_role);
await m_new_member.roles.add(m_rank_role);
await c_new_member.roles.add(c_rank_role);
await m_new_member.roles.add(m_role);
await c_new_member.roles.add(c_role);

const uu3 = await interaction.guild.members.fetch(club_data.owner);

let m_table = database.get(`guilds.${name}.members`);
m_table = m_table.filter(value => value !== uu3.user.username);

database.set(`guilds.${name}.members`, m_table);
database.push(`guilds.${name}.members`, user.username);

database.set(`guilds.${name}.owner`, user.id);
database.set(`users.${user.id}.club`, old_owner.club);
database.set(`users.${user.id}.club_role`, old_owner.club_role);
database.set(`users.${club_data.owner}.club`, "");
database.set(`users.${club_data.owner}.club_role`, "");

interaction.reply({ content: "`[ ✔️ ]` Pomyślnie zmieniłeś prezesa klubu **" + name + "** na <@" + user.id + ">!", ephemeral: true });
}
18 replies
DIAdiscord.js - Imagine an app
Created by n4a on 2/4/2024 in #djs-questions
Error
node:events:491 throw er; // Unhandled 'error' event ^ DiscordAPIError[10007]: Unknown Member at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:722:13)
6 replies
DIAdiscord.js - Imagine an app
Created by n4a on 2/4/2024 in #djs-questions
Invalid Form Body
/home/container/node_modules/@discordjs/rest/dist/index.js:722 throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[50035]: Invalid Form Body
2 replies
DIAdiscord.js - Imagine an app
Created by n4a on 2/4/2024 in #djs-questions
Unknown interaction
DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[10062]: Unknown interaction
const target_data = await database.get(`users.${user.id}`);

if (!target_data) {
await database.set(`users.${user.id}`, {
club: "",
club_role: "",
pass_block: new Date().getTime(),
balance: 0,
});

return interaction.reply({ content: "`[ ✔️ ]` Pomyślnie utworzono konto użytkownika <@" + user.id + ">, użyj komendy ponownie!", ephemeral: true });
}

if (target_data.club) return interaction.reply({ content: "`[ ❌ ]` Podany gracz jest już w klubie!", ephemeral: true });

if (new Date().getTime() < target_data.pass_block) return interaction.reply({ content: "\`[ ✔️ ]\` Użytkownik posiada aktywną blokadę podań!", ephemeral: true });

if (!contracts[user.id]) contracts[user.id] = [];
for (i = 0; i < contracts[user.id].length; i++) {
if (contracts[user.id][i].club === club_data.name && contracts[user.id][i].end > new Date().getTime()) return interaction.reply({ content: "`[ ❌ ]` Wysłałeś już oferte kontraktu!", ephemeral: true });
};

contracts[user.id].push({
"club": club_data.name,
"rank": rank,
"end": 0,
"mId": 0,
});

let current_contract = contracts[user.id][contracts[user.id].length - 1];

current_contract.end = new Date().getTime() + (12 * 3600000);
let time = Date.parse(new Date(new Date().getTime() + (12 * 3600000))) / 1000;

const embed = {
title: "`🎫` IFL - Oferta kontraktu",
description: "Dostałeś ofertę podpisania kontraktu od klubu **" + club_data.name + "**!",
fields: [
{
name: '`🕐` Wygasa za:',
value: "<t:" + time + ":R>",
inline: true,
},
{
name: '`🎖️` Posada:',
value: rank,
inline: true,
},
{
name: '`👤` Prezes:',
value: interaction.user.username,
inline: true,
},
],
timestamp: new Date().toISOString(),
footer: {
text: interaction.user.username + " | " + interaction.user.id,
icon_url: interaction.user.avatarURL(),
},
image: {
url: "https://imgur.com/MjTK8Dn.png",
},
color: Colors.White,
};

const button_accept = new ButtonBuilder()
.setCustomId('CONTRACT_ACCEPT_BUTTON')
.setLabel('Podpisz kontrakt!')
.setStyle(ButtonStyle.Primary);

const button_reject = new ButtonBuilder()
.setCustomId('CONTRACT_REJECT_BUTTON')
.setLabel('Odrzuć kontrakt!')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(button_accept, button_reject);

user.send({ embeds: [embed], components: [row] }).then(message => {
current_contract.mId = message.id;

fs.writeFileSync("data/contracts.json", JSON.stringify(contracts));

interaction.reply({ content: "\`[ ✔️ ]\` Pomyślnie wysłano ofertę kontraktu do <@" + user.id + ">!", ephemeral: true });
}).catch(error => {
interaction.reply({ content: "\`[ ❌ ]\` Podana osoba ma wyłączone wiadomości prywatne!", ephemeral: true });
});
const target_data = await database.get(`users.${user.id}`);

if (!target_data) {
await database.set(`users.${user.id}`, {
club: "",
club_role: "",
pass_block: new Date().getTime(),
balance: 0,
});

return interaction.reply({ content: "`[ ✔️ ]` Pomyślnie utworzono konto użytkownika <@" + user.id + ">, użyj komendy ponownie!", ephemeral: true });
}

if (target_data.club) return interaction.reply({ content: "`[ ❌ ]` Podany gracz jest już w klubie!", ephemeral: true });

if (new Date().getTime() < target_data.pass_block) return interaction.reply({ content: "\`[ ✔️ ]\` Użytkownik posiada aktywną blokadę podań!", ephemeral: true });

if (!contracts[user.id]) contracts[user.id] = [];
for (i = 0; i < contracts[user.id].length; i++) {
if (contracts[user.id][i].club === club_data.name && contracts[user.id][i].end > new Date().getTime()) return interaction.reply({ content: "`[ ❌ ]` Wysłałeś już oferte kontraktu!", ephemeral: true });
};

contracts[user.id].push({
"club": club_data.name,
"rank": rank,
"end": 0,
"mId": 0,
});

let current_contract = contracts[user.id][contracts[user.id].length - 1];

current_contract.end = new Date().getTime() + (12 * 3600000);
let time = Date.parse(new Date(new Date().getTime() + (12 * 3600000))) / 1000;

const embed = {
title: "`🎫` IFL - Oferta kontraktu",
description: "Dostałeś ofertę podpisania kontraktu od klubu **" + club_data.name + "**!",
fields: [
{
name: '`🕐` Wygasa za:',
value: "<t:" + time + ":R>",
inline: true,
},
{
name: '`🎖️` Posada:',
value: rank,
inline: true,
},
{
name: '`👤` Prezes:',
value: interaction.user.username,
inline: true,
},
],
timestamp: new Date().toISOString(),
footer: {
text: interaction.user.username + " | " + interaction.user.id,
icon_url: interaction.user.avatarURL(),
},
image: {
url: "https://imgur.com/MjTK8Dn.png",
},
color: Colors.White,
};

const button_accept = new ButtonBuilder()
.setCustomId('CONTRACT_ACCEPT_BUTTON')
.setLabel('Podpisz kontrakt!')
.setStyle(ButtonStyle.Primary);

const button_reject = new ButtonBuilder()
.setCustomId('CONTRACT_REJECT_BUTTON')
.setLabel('Odrzuć kontrakt!')
.setStyle(ButtonStyle.Secondary);

const row = new ActionRowBuilder()
.addComponents(button_accept, button_reject);

user.send({ embeds: [embed], components: [row] }).then(message => {
current_contract.mId = message.id;

fs.writeFileSync("data/contracts.json", JSON.stringify(contracts));

interaction.reply({ content: "\`[ ✔️ ]\` Pomyślnie wysłano ofertę kontraktu do <@" + user.id + ">!", ephemeral: true });
}).catch(error => {
interaction.reply({ content: "\`[ ❌ ]\` Podana osoba ma wyłączone wiadomości prywatne!", ephemeral: true });
});
2 replies
DIAdiscord.js - Imagine an app
Created by n4a on 2/3/2024 in #djs-questions
Problem with found user in specific guild
I cant find and add role user in specific guild. Here is my code:
const main_guild = interaction.client.guilds.cache.get(main_guild_id);
const clubs_guild = interaction.client.guilds.cache.get(clubs_guild_id);

if (!main_guild || !clubs_guild) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć gildii!", ephemeral: true });

const main_guild_member = main_guild.members.cache.find(member => member.id === interaction.user.id);
const clubs_guild_member = clubs_guild.members.cache.find(member => member.id === interaction.user.id);

if (!main_guild_member || !clubs_guild_member) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć użytkownika!", ephemeral: true });

const main_guild_role = main_guild.roles.cache.find(role => role.name === "• " + club_name + " | Kluby");
const club_guild_role = clubs_guild.roles.cache.find(role => role.name === club_name + " | Kluby");
const club_guild_rank_role = clubs_guild.roles.cache.find(role => role.name === "✧ " + club_rank + " | IFL");

if (!main_guild_role || !club_guild_role || !club_guild_rank_role) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć roli!", ephemeral: true });

main_guild_member.roles.add(main_guild_role);
clubs_guild_member.roles.add(club_guild_role);
clubs_guild_member.roles.add(club_guild_rank_role);
const main_guild = interaction.client.guilds.cache.get(main_guild_id);
const clubs_guild = interaction.client.guilds.cache.get(clubs_guild_id);

if (!main_guild || !clubs_guild) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć gildii!", ephemeral: true });

const main_guild_member = main_guild.members.cache.find(member => member.id === interaction.user.id);
const clubs_guild_member = clubs_guild.members.cache.find(member => member.id === interaction.user.id);

if (!main_guild_member || !clubs_guild_member) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć użytkownika!", ephemeral: true });

const main_guild_role = main_guild.roles.cache.find(role => role.name === "• " + club_name + " | Kluby");
const club_guild_role = clubs_guild.roles.cache.find(role => role.name === club_name + " | Kluby");
const club_guild_rank_role = clubs_guild.roles.cache.find(role => role.name === "✧ " + club_rank + " | IFL");

if (!main_guild_role || !club_guild_role || !club_guild_rank_role) return interaction.reply({ content: "\`[ ❌ ]\` Nie udało się znaleźć roli!", ephemeral: true });

main_guild_member.roles.add(main_guild_role);
clubs_guild_member.roles.add(club_guild_role);
clubs_guild_member.roles.add(club_guild_rank_role);
27 replies
DIAdiscord.js - Imagine an app
Created by n4a on 1/19/2024 in #djs-questions
Events.MessageCreate don't work
const { Events } = require('discord.js'); module.exports = { name: Events.MessageCreate, execute() { console.log('message'); }, }; this event is successfully loaded but don't work. when i send message totally nothing was happening. 0 errors or something other
6 replies