0

A little note to start with, this is a typescript file. I am having trouble with a purge/clear command. This command worked on discord v11 however is having an issue on v12. the issue I am seeing is bulkDelete does not exist on type 'TextChannel | DMChannel | NewsChannel' I don't know where it is going wrong. I am not looking for just a fix, an explanation of why it doesn't work would be appreciated. Thanks in advance!

import * as Discord from "discord.js";
import { IBotCommand } from "../api";

export default class purge implements IBotCommand {
    
    private readonly _command = "purge"
    
    help(): string {
        return "(Admin only) Deletes the desired numbers of messages.";
    }
    
    isThisCommand(command: string): boolean {
        return command === this._command;
    }

    async runCommand(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
        
        //converts args into a number
        let numberOfMessagesToDelete = parseInt(args[0],10);
        //make sure number is interger
        numberOfMessagesToDelete = Math.round(numberOfMessagesToDelete + 1);
        //clean up msgs
        msgObject.delete()
            .catch(console.error);

        if(!msgObject.member.hasPermission("KICK_MEMBERS")) {
            msgObject.channel.send(`${msgObject.author.username}, AH! AH! AH! You didn't say the magic word!`)
                .then(msg => {
                    (msg as Discord.Message).delete({timeout:10000})
                });
            return;
        }
            //message amount
        if(!args[0]){
            msgObject.channel.send(`Improper format! Proper format is "-purge 12"`)
                .then(msg => {
                    (msg as Discord.Message).delete({timeout:10000})
                        .catch(console.error);
                });
            return;    
        }
        //verifies args[0] actual number
        if(isNaN(numberOfMessagesToDelete)){
        
            msgObject.channel.send(`Improper number! Pick a number between 1 and 99!`)
            .then(msg => {
                (msg as Discord.Message).delete({timeout:10000})
                .catch(console.error);
            });
            return;
        }
        //delete desired number of messages

            let auditLog = client.channels.cache.find(channel => channel.id === "623217994742497290") as Discord.TextChannel;
            const bdEmbed = new Discord.MessageEmbed()
            .setTitle(`**Message Purge**`)
            .setDescription(`${numberOfMessagesToDelete} messages were deleted in ${msgObject.channel.toString()} by ${msgObject.author.username}`)
            .setTimestamp()
            .setColor([38,92,216])
            .setThumbnail(msgObject.author.displayAvatarURL())

            msgObject.channel.bulkDelete(numberOfMessagesToDelete)

            auditLog.send(bdEmbed)
            .catch(console.error);   
    }
}
mudeki
  • 33
  • 5
  • Could you quote the actual error? – Lioness100 Oct 30 '20 at 10:43
  • any Property 'bulkDelete' does not exist on type 'TextChannel | DMChannel | NewsChannel'. Property 'bulkDelete' does not exist on type 'DMChannel'.ts(2339) – mudeki Oct 30 '20 at 15:54
  • Yeah, `DMChannel.bulkDelete()` doesn't exist, but it's weird because [`TextChannel.bulkDelete()`](https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=bulkDelete) and [`NewsChannel.bulkDelete()`](https://discord.js.org/#/docs/main/stable/class/NewsChannel?scrollTo=bulkDelete) do. – Lioness100 Oct 30 '20 at 16:03
  • This is a purge command for a channel in our discord though, not a DMChannel. Unless a DMChannel is not a DM between members and I am thinking incorrectly.However if that is the case, what changed between v11 and 12 to not allow the same code to work on both? – mudeki Oct 30 '20 at 16:16
  • 1
    I have an update. I added the code to the js file and it worked like it is supposed to so the problem looks to be with typescript – mudeki Nov 01 '20 at 04:56

0 Answers0