matrix-org / matrix-appservice-discord

A bridge between Matrix and Discord.
Apache License 2.0
809 stars 151 forks source link

Self-Service Bridging Throws TypeError: Cannot read property 'hasPermission' of null #633

Open fhrach4 opened 3 years ago

fhrach4 commented 3 years ago

When trying to use self-service bridging to re-bridge rooms after a re-install, the following error is thrown when !matrix approve is sent by an administrator on Discord.

Nov-28 14:10:55.264 [DiscordBot] error: Caught while handing 'message' TypeError: Cannot read property 'hasPermission' of null
    at permission.every (/home/matrix/matrix-appservice-discord/src/discordcommandhandler.ts:108:55)
    at Array.every (<anonymous>)
    at DiscordCommandHandler.<anonymous> (/home/matrix/matrix-appservice-discord/src/discordcommandhandler.ts:108:31)
    at Generator.next (<anonymous>)
    at /home/matrix/matrix-appservice-discord/build/src/discordcommandhandler.js:22:71
    at new Promise (<anonymous>)
    at __awaiter (/home/matrix/matrix-appservice-discord/build/src/discordcommandhandler.js:18:12)
    at permissionCheck (/home/matrix/matrix-appservice-discord/src/discordcommandhandler.ts:104:94)
    at Function.<anonymous> (/home/matrix/matrix-appservice-discord/src/util.ts:311:37)
    at Generator.next (<anonymous>)
    at /home/matrix/matrix-appservice-discord/build/src/util.js:22:71
    at new Promise (<anonymous>)
    at __awaiter (/home/matrix/matrix-appservice-discord/build/src/util.js:18:12)
    at Function.ParseCommand (/home/matrix/matrix-appservice-discord/build/src/util.js:256:16)
    at DiscordCommandHandler.<anonymous> (/home/matrix/matrix-appservice-discord/src/discordcommandhandler.ts:111:34)
    at Generator.next (<anonymous>)
    at /home/matrix/matrix-appservice-discord/build/src/discordcommandhandler.js:22:71
    at new Promise (<anonymous>)
    at __awaiter (/home/matrix/matrix-appservice-discord/build/src/discordcommandhandler.js:18:12)
    at DiscordCommandHandler.Process (/home/matrix/matrix-appservice-discord/build/src/discordcommandhandler.js:35:16)
    at DiscordBot.<anonymous> (/home/matrix/matrix-appservice-discord/src/bot.ts:778:46)
    at Generator.next (<anonymous>)

Steps to reproduce:

  1. create a fresh install with a clean Discord.db (an existing one should have the same error as well, but I am unable to verify if that is the case since I no longer have a working install with data in Discord.db)
  2. follow the setup steps as normal
  3. invite @_discord_bot to a matrix room and attempt to bridge with a discord room with !discord bridge <guildId> <roomId>
  4. authorize the bridge attempt in Discord

Synapse version: 1.23.0 This happened both with matrix-appservice-discord: 0.5.2 (4cc90e6) and the latest build from master (ce5c8f9)

Half-Shot commented 3 years ago

That's unusual, does this happen for one user or multiple ones? It's interesting that the discordMember object is undefined?

fhrach4 commented 3 years ago

I think I found the underlying issue for this particular error.

As long as one room is joined the 'normal' way through non-self-service bridging, all subsequent requests appear to work as expected.

When I invited the bot to the guild, had already bridged all of the rooms I had wanted to bridge previously, so, all of the rooms were already created in Matrix. I created a new room and then joined it using /join #_discord_guildId_channelId and then used !discord bridge guildId ChannelId on one of the existing channels, and then it worked.

My bridge still isn't working, but at least I'm getting a different error.