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

Closed
opened 2026-02-16 12:26:50 -05:00 by yindo · 2 comments
Owner

Originally created by @WlodekM on GitHub (May 26, 2024).

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

Originally created by @WlodekM on GitHub (May 26, 2024). ### 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: ```js 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
yindo added the bug label 2026-02-16 12:26:50 -05:00
yindo closed this issue 2026-02-16 12:26:51 -05:00
Author
Owner

@amycatgirl commented on GitHub (Sep 22, 2024):

I've already explained my findings inside the Revolt server, but in summary:

  • A member leaves the server the bot is currently in
  • The client receives both ServerMemberLeave and ServerDelete
  • Since ServerDelete was received, the client deletes the server and it's channels from their respective collections
  • Then, when another member sends a message in one of those deleted channels, it attempts to update the channel's lastMessageId property
  • Since that channel does not exist, the code throws an unhandled exception and aborts

This is the code that deletes the channels.

My suggestion to this issue, for the time being, is commenting out this piece of code until ServerDelete can tell the client that the event is a leave or a delete on the client's end.

@amycatgirl commented on GitHub (Sep 22, 2024): I've already explained my findings inside the Revolt server, but in summary: - A member leaves the server the bot is currently in - The client receives both `ServerMemberLeave` and `ServerDelete` - Since `ServerDelete` was received, the client deletes the server and it's channels from their respective collections - Then, when another member sends a message in one of those deleted channels, it attempts to update the channel's `lastMessageId` property - Since that channel does not exist, the code throws an unhandled exception and aborts [This](https://github.com/revoltchat/revolt.js/blob/0a296d8add6b973adb92d0bfc51af84a64ef404e/src/classes/Server.ts#L409-L411) is the code that deletes the channels. My suggestion to this issue, for the time being, is commenting out this piece of code until `ServerDelete` can tell the client that the event is a leave or a delete on the client's end.
Author
Owner

@insertish commented on GitHub (Oct 16, 2024):

Does "client receives" imply the bot is receiving the ServerDelete for the member?
I was noticing some strange behaviour with member leaves, this might be a backend bug.

Also, https://github.com/revoltchat/backend/releases/tag/20240710-1 includes a change that adds the reason to ServerMemberLeave.

@insertish commented on GitHub (Oct 16, 2024): Does "client receives" imply the bot is receiving the `ServerDelete` for the member? I was noticing some strange behaviour with member leaves, this might be a backend bug. Also, https://github.com/revoltchat/backend/releases/tag/20240710-1 includes a change that adds the `reason` to `ServerMemberLeave`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stoatchat/javascript-client-sdk#36