sky
sky
DIAdiscord.js - Imagine an app
Created by sky on 7/17/2023 in #djs-questions
Counting Deleted Channels
How do I do that?
4 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/17/2023 in #djs-questions
Counting Deleted Channels
client.on('channelDelete', async (channel) => {
const guild = client.guilds.cache.get(client.main_db.get('guild'));

if (!guild) return;

const category = guild.channels.cache.get(client.main_db.get('category'));

if (channel.type !== ChannelType.GuildText) return;
if ((channel as TextChannel).parentId !== category.id) return;

const ticketsCategoryChannel = client.channels.cache.get(category.id) as CategoryChannel
const numTickets = ticketsCategoryChannel.children.cache.size;
const numClosed = !ticketsCategoryChannel.children.cache.size;
const channel1 = guild.channels.cache.find((channel) => channel.name === client.user.id && channel.parentId === category.id && channel.type === ChannelType.GuildText);
const channel2 = client.channels.cache.get('1127093969164177478') as TextChannel;

const ticketsEmbedMessage = channel2.messages.cache.get(ticketsEmbedMessageId);
await ticketsEmbedMessage.edit({
embeds: [
new EmbedBuilder()
.setAuthor({
name: "ModMail",
iconURL: client.user.displayAvatarURL()
})
.setTitle("ModMail Stats")
.setDescription("Status: **`✅` Online**")
.addFields(
{ name: 'Open Tickets', value: "✅ " + `${numTickets}` },
{ name: 'Resolved Tickets', value: "❌ " + `${numClosed}`}
)
.setColor('Blurple')
.setImage(client.user.avatarURL())
]
});


const user = client.users.cache.get(channel.name);

if (!user) return;

user.send({
embeds: [
warningEmbed('Your mail has been deleted. Please do not send any message, now, to avoid creating new mail for no reason.')
]
}).catch(() => { });
});
client.on('channelDelete', async (channel) => {
const guild = client.guilds.cache.get(client.main_db.get('guild'));

if (!guild) return;

const category = guild.channels.cache.get(client.main_db.get('category'));

if (channel.type !== ChannelType.GuildText) return;
if ((channel as TextChannel).parentId !== category.id) return;

const ticketsCategoryChannel = client.channels.cache.get(category.id) as CategoryChannel
const numTickets = ticketsCategoryChannel.children.cache.size;
const numClosed = !ticketsCategoryChannel.children.cache.size;
const channel1 = guild.channels.cache.find((channel) => channel.name === client.user.id && channel.parentId === category.id && channel.type === ChannelType.GuildText);
const channel2 = client.channels.cache.get('1127093969164177478') as TextChannel;

const ticketsEmbedMessage = channel2.messages.cache.get(ticketsEmbedMessageId);
await ticketsEmbedMessage.edit({
embeds: [
new EmbedBuilder()
.setAuthor({
name: "ModMail",
iconURL: client.user.displayAvatarURL()
})
.setTitle("ModMail Stats")
.setDescription("Status: **`✅` Online**")
.addFields(
{ name: 'Open Tickets', value: "✅ " + `${numTickets}` },
{ name: 'Resolved Tickets', value: "❌ " + `${numClosed}`}
)
.setColor('Blurple')
.setImage(client.user.avatarURL())
]
});


const user = client.users.cache.get(channel.name);

if (!user) return;

user.send({
embeds: [
warningEmbed('Your mail has been deleted. Please do not send any message, now, to avoid creating new mail for no reason.')
]
}).catch(() => { });
});
4 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
The code that I sent above I found off a tutorial, so I do not know how to proceed. I am a beginner.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
I know.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
No, because there is absolutely no example on that website that is in regards of Discord's API.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
Yes.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
I did not say I don't know how to call a function. I'm saying I do not know how to implement "setTimeout." This is literally my first day ever hearing about it.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
how logical
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
me: go fly a plane you: i don't know how me: that's basic flight
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
Gee! It's all clear to me, now! Thanks for your condescending remark that has made it utterly clear to me on how to proceed!
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
Correct!
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
I already informed you that I do not know how to do so.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
Message regarding the above code is sent above "d.js tookit's" message.
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
client.bans_db.set(user.id, time && reason);

await interaction.reply({
embeds: [
successEmbed('The user <@' + user.id + '> has been successfully banned')
]
});

return;
}
});
client.bans_db.set(user.id, time && reason);

await interaction.reply({
embeds: [
successEmbed('The user <@' + user.id + '> has been successfully banned')
]
});

return;
}
});
27 replies
DIAdiscord.js - Imagine an app
Created by sky on 7/5/2023 in #djs-questions
TypeScript Logical Error Not Syntax Error
import { Command } from "../../class/Command";
import { SlashCommandBuilder } from "discord.js";
import { errorEmbed, successEmbed } from "../../util/functions";
import { toMs, fromMs } from 'ms-typescript';

export default new Command({
command_data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a guild member from using the ModMail system.')
.addUserOption((opt) =>
opt.setName('user')
.setDescription('The user to ban.')
.setRequired(true)
)
.addStringOption((opt) =>
opt.setName('duration')
.setDescription('The duration of the ban. (use s, m, d, w... etc.)')
.setRequired(false)
)
.addStringOption((opt) =>
opt.setName('reason')
.setDescription('The reason for the ban.')
.setRequired(false)
)
.setDMPermission(false)
.toJSON(),
run: async (client, interaction, args) => {
const user = args.getUser('user');
const time = toMs(args.getString('duration') ?? '0');
const reason = args.getString('reason') || 'No reason was provided';

if (time <= 0 || time > 2419200000) {
await interaction.reply({
content: 'The time must be between **1 second** and **28 days**.'
});

return;
};

const member = interaction.guild?.members.cache.get(user.id);

let data_check = client.bans_db.get(user.id);

if (data_check) {
await interaction.reply({
embeds: [
errorEmbed('The user is already banned.')
],
ephemeral: true
});

return;
};
import { Command } from "../../class/Command";
import { SlashCommandBuilder } from "discord.js";
import { errorEmbed, successEmbed } from "../../util/functions";
import { toMs, fromMs } from 'ms-typescript';

export default new Command({
command_data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban a guild member from using the ModMail system.')
.addUserOption((opt) =>
opt.setName('user')
.setDescription('The user to ban.')
.setRequired(true)
)
.addStringOption((opt) =>
opt.setName('duration')
.setDescription('The duration of the ban. (use s, m, d, w... etc.)')
.setRequired(false)
)
.addStringOption((opt) =>
opt.setName('reason')
.setDescription('The reason for the ban.')
.setRequired(false)
)
.setDMPermission(false)
.toJSON(),
run: async (client, interaction, args) => {
const user = args.getUser('user');
const time = toMs(args.getString('duration') ?? '0');
const reason = args.getString('reason') || 'No reason was provided';

if (time <= 0 || time > 2419200000) {
await interaction.reply({
content: 'The time must be between **1 second** and **28 days**.'
});

return;
};

const member = interaction.guild?.members.cache.get(user.id);

let data_check = client.bans_db.get(user.id);

if (data_check) {
await interaction.reply({
embeds: [
errorEmbed('The user is already banned.')
],
ephemeral: true
});

return;
};
27 replies