#Discord.JS : How do I add a time/duration to blocking someone from ModMail?

13 messages · Page 1 of 1 (latest)

tall wedge
#

I have this TypeScript code for blocking someone from ModMail via a slash command. Although the slash command gives the option to add a time, the block ends up being permanent, even if a duration is added. Please help. Thank you.

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

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

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

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

        return;
    }
});
velvet tartan
#

client.bans_db.set(user.id, time && reason) doesn't do what you probably want it to. time && reason will either return time if it is null or undefined or it will return reason if time is not null/undefined. It will not combine the two properties into a single object or something.
What type does that second argument of client.bans_db.set expect if you hover over the method? And where does client.bans_db even come from, since that's not a standard property on the discord.js client object? If it's a field you've added it'll help to see how you defined it and how it's being used.

tall wedge
#

@velvet tartan oh hi! i wouldve dmd u again but i figured ive possibly been annoying u given the amount of times ive dmd u lately lol

tall wedge
#

client.bans_db i believe comes from JSONDatabase

velvet tartan
#

the value argument should really not be any since that gives you no type safety when calling that function. can you show me where the bans_db stuff is defined in the client? is it a custom class you wrote, or if not can you show the code you use to import whatever other library you're using to create that custom client?

#

cause the more pressing issue currently isnt with your /ban command (although that will need changes), it's with the client.bans_db (wherever that's coming from) not having the correct typings

tall wedge
#

also in this code here

how do i make it so that the bot first responds to the USER in an Aqua embedded message but then every message after that is green

the bot successfully does so in which the user sends the BOT a message but not the other way around

don't know y

tall wedge
#

im not that good with for loops

tall wedge
#

i apologize if i'm requesting too much

velvet tartan
# tall wedge <@983491151648653372> got it from this site: https://github.com/TFAGaming/Discor...

soooo, you're saying you just pulled in all the code from that repo without understanding how any of it works or what the repercussions are of using it? that's a pretty bad idea. if you want to actually learn programming, dont just copy code, or if you do at least make sure you understand all of what you're copying. start with a simple bot you built up yourself and extend it to have the functionality you need in a way that you actually understand. trying to work with someone elses code that was implemeted in the way that made sense to them isn't going to help you learn at all. and as you've seen, working around the issues it has due to the way they chose to implement it is going to be more difficult than just building the functionality yourself in the end.