revoltchat / revolt.js

Modern Typescript library for interacting with Revolt.
https://revolt.js.org
MIT License
216 stars 54 forks source link

TypeError: Cannot read properties of undefined (reading 'lastMessageId') #96

Open WlodekM opened 1 month ago

WlodekM commented 1 month ago

What happened?

my bot crashes when i use the kick command Full error:

C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\solid-js\store\dist\server.cjs:67
    next = current[part];
                  ^

TypeError: Cannot read properties of undefined (reading 'lastMessageId')
    at updatePath (C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\solid-js\store\dist\server.cjs:67:19)
    at updatePath (C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\solid-js\store\dist\server.cjs:64:7)
    at ChannelCollection.setStore [as updateUnderlyingObject] (C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\solid-js\store\dist\server.cjs:83:66)
    at C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\revolt.js\lib\cjs\events\v1.js:77:41
    at batch (C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\solid-js\dist\server.cjs:105:10)
    at C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\revolt.js\lib\cjs\events\v1.js:75:42
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\wlodz\Projects\revoltBots\construct\construct\node_modules\revolt.js\lib\cjs\events\v1.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

kick command code:

import { replyWithErr } from "../lib.js";

const log = console.log

export default {
    name: 'kick',
    aliases: [],
    // privilege: CommandPrivilege.Manager,
    async run(message, args, command, db, bot, { client }) {
        const isOwner = message.author.id == bot.owner.id
        if (!(isOwner || message.member.hasPermission(message.server, "KickMembers"))) { replyWithErr(message, "Missing permission"); return }
        if (message.server.ownerId == message.mentionIds[0]) { replyWithErr(message, "Unable to kick owner"); return }
        if (message.mentionIds == undefined) { replyWithErr(message, "Missing argument 1"); return }
        if (message.mentionIds[0] == bot.id) { replyWithErr(message, "I can't kick myself!"); return }
        var myRank = await message.server.fetchMember(bot.id).ranking
        var targetRank = await message.server.fetchMember(message.mentionIds[0]).ranking

        if (myRank > targetRank) { replyWithErr(message, "My rank is lower than the rank of the person you are trying to kick"); return }

        try {
            message.server.kickUser(message.mentionIds[0])
        } catch (err) {
            log(`! Fatal Error: ${err}`)
            console.log(err)
            message.reply("someting went wrong, check if the bot has permission to kick/ban and try again!")
            return
        }
        try {
            if (message.server.id == "01H36T7ZNX7ZMQ4FKB2TZHKX04") {
                Array.prototype.random = function() {
                    return this[Math.floor(Math.random() * this.length)]
                }
                let killers = [
                    ':01HJ1E0VN82X9HY5NZTDK93NJF:',
                    ':01HKF2GPK971GA0XP5DQQ3F78B:',
                    ':01HKJBBYTGFT42EKC6HYHDZVDT:',
                    ':01HKJBD22G8WA376S10VPZJP5X:',
                    ':01HKJBV6E07JG64HP7HSV450GA:',
                    ':01HKJC0KPYX980T3ARTBH4W97K:',
                    ':01HKJC124ZVN8JXRZ478X65ZCG:',
                    ':01HKJBWN7A59Q0K3AKCE37BJJN:',
                    ':01HKJBX09P4Z8NTBEZDHN09K61:',
                ];
                let weepons = [
                    ':01H36VVBSK3C72AFNGSFT6HQQ1:',
                    ':01H36VVSHZJS8JPZ55ZNCA0N08:',
                    ':01H36VWDPEQ3EYNEDRR933311E:',
                    ':01H36VWZ54FN14YV4ABYARAT22:',
                    ':01H36VXB1CJTM070PBZXAGGNY4:',
                    ':01H36VXVGQQZ9YQX5X991NA9PH:',
                    ':01H36VYF63ZNMN3Y0NKSQN3W5Z:',
                ];
                try {
                    if (client.channels.get("01H8A1BFF1F2Q2AT6629WC6A4Q")) {
                        client.channels.get("01H8A1BFF1F2Q2AT6629WC6A4Q").sendMessage(`${killers.random()}${weepons.random()}${message.args[0]}`)
                    }
                } catch (fatalError) {
                    log(`! Fatal Error: ${fatalError}`)
                    console.log(JSON.stringify(fatalError))
                }
            } else {
                try {
                    message.channel.sendMessage(`<@${message.mentionIds[0]}> kicked`)
                } catch (fatalError) {
                    log(`! Fatal Error: ${fatalError}`)
                    console.log(JSON.stringify(fatalError))
                }
            }
        } catch (fatalError) {
            log(`! Fatal Error: ${fatalError}`)
            console.log(JSON.stringify(fatalError))
        }
    },
}

it gets to the client.channels.get("01H8A1BFF1F2Q2AT6629WC6A4Q").sendMessage(`${killers.random()}${weepons.random()}${message.args[0]}`) part before crashing pls help