Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WlodekM opened this issue May 26, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@WlodekM
Copy link

WlodekM commented 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

@WlodekM WlodekM added the bug Something isn't working label May 26, 2024
@amycatgirl
Copy link

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.

@insertish
Copy link
Member

insertish commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🆕 Untriaged
Development

No branches or pull requests

3 participants