Pooyan
Pooyan
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/2/2023 in #djs-questions
Check if a user has Nitro or not
Is there anyway to check if a member/user has Nitro or no in discord.js@13/14 ?
9 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 8/2/2023 in #djs-questions
Discord Invites
Hey, Can someone explain me how can I fetch invites (who invited the member & what is the invite code) in both [email protected] and [email protected] ?
4 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 7/18/2023 in #djs-questions
Client only deploys 3-4 slash commands
Hey, I have 7 slash commands that I want to deploy but I can't (it only deploys 3 or 4).
const { REST, Routes } = require("discord.js");
const fs = require("fs");
const clientId = "1111931372249022474";
const guildId = "980900531260248104";
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs
.readdirSync(`${path}/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command);
}

const rest = new REST().setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log(
`Started refreshing ${client.slashCommandArray.length} application (/) commands.`
);
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: client.slashCommandArray }
);
console.log(
`Successfully reloaded ${data.length} application (/) commands.`
);
} catch (error) {
console.error(error);
}
})();
}
};
};
const { REST, Routes } = require("discord.js");
const fs = require("fs");
const clientId = "1111931372249022474";
const guildId = "980900531260248104";
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs
.readdirSync(`${path}/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command);
}

const rest = new REST().setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log(
`Started refreshing ${client.slashCommandArray.length} application (/) commands.`
);
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: client.slashCommandArray }
);
console.log(
`Successfully reloaded ${data.length} application (/) commands.`
);
} catch (error) {
console.error(error);
}
})();
}
};
};
Should I wait for client to deploy more or what?
18 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 7/8/2023 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'id')
Hey, I want to make a setlan command for my bot, when it sends the embed, it seems that the collector collects something itsself and the bot gives a "wtf" reply. Can anyone help me fix it? DiscordJS version: 14.11.0 Code:
const { SlashCommandBuilder } = require("@discordjs/builders");
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ComponentType,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("setlan")
.setDescription("Set Your Preferred Language!"),
async execute(interaction, client, profileData, language) {
const embed = new EmbedBuilder()
.setTitle(`${language.changing_language}`)
.setDescription(`> ${language.changing_language_description}`)
.setColor("#FFE700");
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("english")
.setLabel("English")
.setEmoji(":flag_gb:")
.setStyle("Primary"),
new ButtonBuilder()
.setCustomId("persian")
.setLabel("Persian")
.setEmoji(":flag_ir:")
.setStyle("Secondary"),
new ButtonBuilder()
.setCustomId("close_window")
.setLabel("Close window")
.setEmoji(":no_entry:")
.setStyle("Danger")
);
const collector = await interaction.channel.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
});

collector.on("collect", (i) => {
if (i.user.id === interaction.user.id) {
if (i.customId == "english") {
profileData.lang = "English";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"English"
)}`,
});
collector.stop();
} else if (i.customId == "persian") {
profileData.lang = "Persian";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"فارسی"
)}`,
});
collector.stop();
} else if (i.customId == "close_window") {
interaction.deleteReply();
i.deferUpdate();
collector.stop();
} else {
i.reply({ content: "wtf", ephemeral: true });
}
} else {
i.reply({
content: `${language.these_buttons_arent_for_you}`,
ephemeral: true,
});
}
});

collector.on("end", (collected) => {
row.components[0].setDisabled(true);
row.components[1].setDisabled(true);
row.components[2].setDisabled(true);
interaction.editReply({ embeds: [embed], components: [row] });
});
await interaction.reply({ embeds: [embed], components: [row] });
},
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ComponentType,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("setlan")
.setDescription("Set Your Preferred Language!"),
async execute(interaction, client, profileData, language) {
const embed = new EmbedBuilder()
.setTitle(`${language.changing_language}`)
.setDescription(`> ${language.changing_language_description}`)
.setColor("#FFE700");
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("english")
.setLabel("English")
.setEmoji(":flag_gb:")
.setStyle("Primary"),
new ButtonBuilder()
.setCustomId("persian")
.setLabel("Persian")
.setEmoji(":flag_ir:")
.setStyle("Secondary"),
new ButtonBuilder()
.setCustomId("close_window")
.setLabel("Close window")
.setEmoji(":no_entry:")
.setStyle("Danger")
);
const collector = await interaction.channel.createMessageCollector({
time: 300000,
componentType: ComponentType.Button,
});

collector.on("collect", (i) => {
if (i.user.id === interaction.user.id) {
if (i.customId == "english") {
profileData.lang = "English";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"English"
)}`,
});
collector.stop();
} else if (i.customId == "persian") {
profileData.lang = "Persian";
profileData.save();
i.reply({
content: `${language.change_language_success.replace(
"{language}",
"فارسی"
)}`,
});
collector.stop();
} else if (i.customId == "close_window") {
interaction.deleteReply();
i.deferUpdate();
collector.stop();
} else {
i.reply({ content: "wtf", ephemeral: true });
}
} else {
i.reply({
content: `${language.these_buttons_arent_for_you}`,
ephemeral: true,
});
}
});

collector.on("end", (collected) => {
row.components[0].setDisabled(true);
row.components[1].setDisabled(true);
row.components[2].setDisabled(true);
interaction.editReply({ embeds: [embed], components: [row] });
});
await interaction.reply({ embeds: [embed], components: [row] });
},
};
18 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 4/13/2023 in #djs-questions
TypeError: Cannot read properties of undefined (reading 'status')
Why this code stopped working?
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.user.presence.status === 'online').size;
console.log(onlineCount)
const guild = client.guilds.cache.get("944616601678917632");
const onlineCount = guild.members.cache.filter(m => m.user.presence.status === 'online').size;
console.log(onlineCount)
17 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 4/9/2023 in #djs-questions
messageDelete events can't read "id" of the user(message author)
client.on('messageDelete', async (messageDelete) => {

const fetchedLogs = await messageDelete.guild.fetchAuditLogs({
limit: 6,
type: 'MESSAGE_DELETE'
}).catch(console.error);

const auditEntry = fetchedLogs.entries.find(a =>
a.target.id === messageDelete.author.id && // error ("id")
a.extra.channel.id === messageDelete.channel.id &&
Date.now() - a.createdTimestamp < 20000
);
const executor = auditEntry.executor ? auditEntry.executor.tag : 'Unknown';

const DeleteEmbed = new Discord.MessageEmbed()
.setTitle("DELETED MESSAGE")
.setColor("#fc3c3c")
.addField("Author", messageDelete.author.tag, true)
.addField("Deleted By", executor, true)
.addField("Channel", messageDelete.channel, true)
.addField("Message", messageDelete.content || "None")
.setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`);

const DeleteChannel = messageDelete.guild.channels.find(x => x.name === "delete-log");
DeleteChannel.send(DeleteEmbed);
})
client.on('messageDelete', async (messageDelete) => {

const fetchedLogs = await messageDelete.guild.fetchAuditLogs({
limit: 6,
type: 'MESSAGE_DELETE'
}).catch(console.error);

const auditEntry = fetchedLogs.entries.find(a =>
a.target.id === messageDelete.author.id && // error ("id")
a.extra.channel.id === messageDelete.channel.id &&
Date.now() - a.createdTimestamp < 20000
);
const executor = auditEntry.executor ? auditEntry.executor.tag : 'Unknown';

const DeleteEmbed = new Discord.MessageEmbed()
.setTitle("DELETED MESSAGE")
.setColor("#fc3c3c")
.addField("Author", messageDelete.author.tag, true)
.addField("Deleted By", executor, true)
.addField("Channel", messageDelete.channel, true)
.addField("Message", messageDelete.content || "None")
.setFooter(`Message ID: ${messageDelete.id} | Author ID: ${messageDelete.author.id}`);

const DeleteChannel = messageDelete.guild.channels.find(x => x.name === "delete-log");
DeleteChannel.send(DeleteEmbed);
})
13 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 4/1/2023 in #djs-questions
Why channel.type is not working for me without any errors
client.on("messageCreate", async (message) => {
if (message.channel.type === "DM") {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
client.on("messageCreate", async (message) => {
if (message.channel.type === "DM") {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
40 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 2/26/2023 in #djs-questions
data.limitSpotify -= 1 substracts 2 instead of 1 (MongoDB)
Hey, When I want to limit the user so he can only use a command 10 times, the bot substracts 2 of the user's limits, instead of 1.
3 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 2/20/2023 in #djs-questions
How can I make slash command NSFW?
I used .setNSFW but It didn't work
3 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 1/26/2023 in #djs-questions
<function> is not a function
Hey, I have a function out of anything, at top of my code named ticket. It works anywhere else but does not work in a specific line of code. Idk why, but it declares it a parameter instead of a function! + node.js 16 + discord.js v13.12.0 + using mongodb
14 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 1/22/2023 in #djs-questions
How to add choice to slash command?
Hey, I want to add choices to the option named "section", But I don't know how. Can you guide me?
const { Client, CommandInteraction , MessageEmbed } = require("discord.js");

module.exports = {
name: "new-staff",
description: "give role to new staff",
user: ["ADMINISTRATOR"],
options: [
{
name: "user",
description: "The user you want to add the role to",
required: true,
type: "USER"
},
{
name: "section",
description: "The user you want to add the role to",
required: true,
type: "STRING"

}
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {
const section = interaction.options.getString("section")
const user = interaction.options.getMember('user');

if (section === 'mta_roles') {
const mta_roles = ['1000138410075377706', '1000138410268311563'];

mta_roles.forEach(async role => {
let rl = interaction.guild.roles.cache.find(r => r.id == role);
user.roles.add(rl);
await wait(500);
})
await interaction.reply({ content: ':ballot_box_with_check: Success (MTA)', ephemeral: true });
} else if (section === 'fivem_roles') {
const fivem_roles = ['1000138410230558804', '1000138410268311562'];

fivem_roles.forEach(async role => {
let rl = interaction.guild.roles.cache.find(r => r.id == role);
user.roles.add(rl);
await wait(500);
})
await interaction.reply({ content: ':ballot_box_with_check: Success (FIVEM)', ephemeral: true });
}
}
};
const { Client, CommandInteraction , MessageEmbed } = require("discord.js");

module.exports = {
name: "new-staff",
description: "give role to new staff",
user: ["ADMINISTRATOR"],
options: [
{
name: "user",
description: "The user you want to add the role to",
required: true,
type: "USER"
},
{
name: "section",
description: "The user you want to add the role to",
required: true,
type: "STRING"

}
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {
const section = interaction.options.getString("section")
const user = interaction.options.getMember('user');

if (section === 'mta_roles') {
const mta_roles = ['1000138410075377706', '1000138410268311563'];

mta_roles.forEach(async role => {
let rl = interaction.guild.roles.cache.find(r => r.id == role);
user.roles.add(rl);
await wait(500);
})
await interaction.reply({ content: ':ballot_box_with_check: Success (MTA)', ephemeral: true });
} else if (section === 'fivem_roles') {
const fivem_roles = ['1000138410230558804', '1000138410268311562'];

fivem_roles.forEach(async role => {
let rl = interaction.guild.roles.cache.find(r => r.id == role);
user.roles.add(rl);
await wait(500);
})
await interaction.reply({ content: ':ballot_box_with_check: Success (FIVEM)', ephemeral: true });
}
}
};
30 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 12/14/2022 in #djs-questions
No duplicate tickets in discord.js
I want to make my bot to not create another ticket if there is an open ticket by the user requesting this action.
const ticketCategory = interaction.guild.channels.cache.find((c) => c.id === "1052297483952345159");

let existingChannel = interaction.guild.channels.cache.find(c => c.name = `Ticket-${interaction.user.discriminator}`);
if (existingChannel) {
return interaction.reply({ content: '❌ There is already a Ticket opened by you!', ephemeral: true });
} else {
return interaction.reply('test')
}
const ticketCategory = interaction.guild.channels.cache.find((c) => c.id === "1052297483952345159");

let existingChannel = interaction.guild.channels.cache.find(c => c.name = `Ticket-${interaction.user.discriminator}`);
if (existingChannel) {
return interaction.reply({ content: '❌ There is already a Ticket opened by you!', ephemeral: true });
} else {
return interaction.reply('test')
}
19 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 10/26/2022 in #djs-questions
Slash commands being duplicated in global registering
Hey, When I try to register my slash commands globally, they are getting duplicated. Here is the code I am using:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = 'cliend_id';
const guildId = 'guild_id';
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command)
}

const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');
rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.slashCommandArray
})
console.log('Started refreshing application (/) commands.');
} catch (error) {
console.error(error);
}
})();
}
}
}
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = 'cliend_id';
const guildId = 'guild_id';
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command)
}

const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');
rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.slashCommandArray
})
console.log('Started refreshing application (/) commands.');
} catch (error) {
console.error(error);
}
})();
}
}
}
I am using discord.js v13.8.0 and node.js v16
3 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 10/26/2022 in #djs-questions
Slashcommands disappearing after a few minutes
Hey, A few minutes late from when I register slash commands, they disappear and just 2 will remain. What's the problem? [email protected] and node.js 16
2 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 10/2/2022 in #djs-questions
Error registering slash commands discord.js v13
Hey, I am registering my slash commands and I am getting an error several times! and I don't even know what file it is for!
Error: 3.options[1].name[STRING_TYPE_REGEX]: String value did not match validation regex.
Error: 3.options[1].name[STRING_TYPE_REGEX]: String value did not match validation regex.
52 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/29/2022 in #djs-questions
Cannot register slash commands discord.js v13
Every time I start registering my application commands, I get this error:
<rejected> DiscordAPIError[50035]: Invalid Form Body
0[DICT_TYPE_CONVERT]: Only dictionaries may be used in a DictTyp
<rejected> DiscordAPIError[50035]: Invalid Form Body
0[DICT_TYPE_CONVERT]: Only dictionaries may be used in a DictTyp
And they are not registered after a few minutes. Notes: discord.js v13.8.0 node.js v16
4 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/29/2022 in #djs-questions
Error registering a command
I was registering slash commands and I ran to an error: 0[DICT_TYPE_CONVERT]: Only dictionaries may be used in a DictType at SequentialHandler.runRequest (C:\Users\Pooyan\Desktop\PDM Bot\node_modules\@discordjs\rest\dist\index.js:708:15) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.queueRequest (C:\Users\Pooyan\Desktop\PDM Bot\node_modules\@discordjs\rest\dist\index.js:511:14) { rawError: { code: 50035, errors: { '0': [Object] }, message: 'Invalid Form Body' }, code: 50035, status: 400, method: 'put', url: 'https://discord.com/api/v9/applications/966666309909770260/guilds/966987181069598731/commands', requestBody: { files: undefined, json: [ [Array] ] } } Promise { <rejected> DiscordAPIError[50035]: Invalid Form Body 0[DICT_TYPE_CONVERT]: Only dictionaries may be used in a DictType at SequentialHandler.runRequest (C:\Users\Pooyan\Desktop\PDM Bot\node_modules\@discordjs\rest\dist\index.js:708:15) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.queueRequest (C:\Users\Pooyan\Desktop\PDM Bot\node_modules\@discordjs\rest\dist\index.js:511:14) { rawError: { code: 50035, errors: [Object], message: 'Invalid Form Body' }, code: 50035, status: 400, method: 'put', url: 'https://discord.com/api/v9/applications/966666309909770260/guilds/966987181069598731/commands', requestBody: { files: undefined, json: [Array] } } } Notes: discord.js v13.8.0 and node.js v16
10 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/29/2022 in #djs-questions
Discord.js v13 Slash commands are duplicated
Hello , I was registering slash commands but I ran into an error: 24[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique I checked the specified guild and I saw that the commands are duplicated. Why? Code:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = '966666309909770260';
const guildId = '966987181069598731';
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashcommands.set(command.data.name, command)
client.slashCommandArray.push(command.data.toJSON());
}


const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: client.slashCommandArray },
);

console.log('Started refreshing application (/) commands.');
} catch (error) {
console.error(error);
}
})();
}
}
}
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = '966666309909770260';
const guildId = '966987181069598731';
module.exports = (client) => {
client.handleCommands = async (slashCommandFolders, path) => {
client.slashCommandArray = [];
for (folder of slashCommandFolders) {
const slashCommandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
const command = require(`../slashcommands/${folder}/${file}`);
client.slashcommands.set(command.data.name, command)
client.slashCommandArray.push(command.data.toJSON());
}


const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: client.slashCommandArray },
);

console.log('Started refreshing application (/) commands.');
} catch (error) {
console.error(error);
}
})();
}
}
}
Notes: Using discord.js v13.8.0 node.js v16
15 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/27/2022 in #djs-questions
Discord.js v13 Slash command's option depends on the option
Is this possible? Example: /command choice1 choice2 If I select "A" in choice1 I get "One" and "Two" as choices in choice. But when I select "B" in choice1, I will get "Three" and "Four" as choice2 options.
23 replies
DIAdiscord.js - Imagine an app
Created by Pooyan on 9/26/2022 in #djs-questions
Max number of daily application command creates has been reached (200)
Hello, I have 12 slash commands on my bot, and I suddenly got an error: Max number of daily application command creates has been reached (200). I have never gotten this error. Can anyone fix this?
3 replies