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

Message.deletable giving TypeError (possible issue with Channel.permissionsFor) #2319

Closed
2 tasks
iamtraction opened this issue Feb 3, 2018 · 3 comments
Closed
2 tasks

Comments

@iamtraction
Copy link

Please describe the problem you are having in as much detail as possible:

Message.deletable sometimes gives TypeError: Cannot read property 'has' of null.
Upon looking at the discord.js code for Message.deletable, I found that the actual issue is with Channel.permissionsFor() - it sometimes returns null (check the complete stack trace below):

get deletable() {
  return this.author.id === this.client.user.id || (this.guild &&
    this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES)
  );
}

I've previously found that Channel.permissionsFor() returned null sometimes, but I thought that was intended. So, I did a workaround for that when I directly accessed that. But if Message.deletable internally uses that and it gives a TypeError, that's a bug and should be fixed. And so, I'm reporting it.

Include a reproducible code sample here, if possible:

if (msg.deletable) { // L48 - This is the line causing the TypeError.
  msg.delete().catch(e => {
    Bastion.log.error(e);
  });
}

Link to the snippet above: https://github.com/TheBastionBot/Bastion/blob/master/modules/games/acrophobia.js#L48

Complete stack trace of the error:

TypeError: Cannot read property 'has' of null
    at Message.get deletable [as deletable] (/some/directory/Bastion/node_modules/discord.js/src/structures/Message.js:323:52)
    at MessageCollector.collector.on (/some/directory/Bastion/modules/games/acrophobia.js:48:17)
    at emitTwo (events.js:131:20)
    at MessageCollector.emit (events.js:214:7)
    at MessageCollector._handle (/some/directory/Bastion/node_modules/discord.js/src/structures/interfaces/Collector.js:92:10)
    at emitOne (events.js:121:20)
    at Client.emit (events.js:211:7)
    at MessageCreateHandler.handle (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:330:35)
    at WebSocketConnection.onMessage (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:293:17)
    at WebSocket.onMessage (/some/directory/Bastion/node_modules/ws/lib/event-target.js:120:16)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at Receiver._receiver.onmessage (/some/directory/Bastion/node_modules/ws/lib/websocket.js:145:47)
    at Receiver.dataMessage (/some/directory/Bastion/node_modules/ws/lib/receiver.js:430:14)
    at Receiver.getData (/some/directory/Bastion/node_modules/ws/lib/receiver.js:368:12)
    at Receiver.startLoop (/some/directory/Bastion/node_modules/ws/lib/receiver.js:164:16)
    at Receiver.add (/some/directory/Bastion/node_modules/ws/lib/receiver.js:138:10)
    at TLSSocket._ultron.on (/some/directory/Bastion/node_modules/ws/lib/websocket.js:143:54)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
Trace
    at Object.exports.error.message [as error] (/some/directory/Bastion/handlers/logHandler.js:31:11)
    at MessageCollector.collector.on (/some/directory/Bastion/modules/games/acrophobia.js:69:21)
    at emitTwo (events.js:131:20)
    at MessageCollector.emit (events.js:214:7)
    at MessageCollector._handle (/some/directory/Bastion/node_modules/discord.js/src/structures/interfaces/Collector.js:92:10)
    at emitOne (events.js:121:20)
    at Client.emit (events.js:211:7)
    at MessageCreateHandler.handle (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:330:35)
    at WebSocketConnection.onMessage (/some/directory/Bastion/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:293:17)
    at WebSocket.onMessage (/some/directory/Bastion/node_modules/ws/lib/event-target.js:120:16)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at Receiver._receiver.onmessage (/some/directory/Bastion/node_modules/ws/lib/websocket.js:145:47)
    at Receiver.dataMessage (/some/directory/Bastion/node_modules/ws/lib/receiver.js:430:14)
    at Receiver.getData (/some/directory/Bastion/node_modules/ws/lib/receiver.js:368:12)
    at Receiver.startLoop (/some/directory/Bastion/node_modules/ws/lib/receiver.js:164:16)
    at Receiver.add (/some/directory/Bastion/node_modules/ws/lib/receiver.js:138:10)
    at TLSSocket._ultron.on (/some/directory/Bastion/node_modules/ws/lib/websocket.js:143:54)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)

Further details:

  • discord.js version: 11.3.0
  • node.js version: 8.9.4
  • Operating system: Debian 9.1 x64
  • Priority this issue should have – please be realistic and elaborate if possible:
    Medium - Because it doesn't happen all the time. I've got 6 logs of this error since last Sunday.
  • I found this issue while running code on a user account
  • I have also tested the issue on latest master, commit hash:
@SpaceEEC
Copy link
Member

SpaceEEC commented Feb 5, 2018

I backported #2026 with 3df3741, which would fix your issue if the cause is the bot leaving and rejoining a guild.
This is probably not the only cause of the own member being uncached as you can read up in #1870.

If you have any idea on reproducing this feel free to let me know.

@iamtraction
Copy link
Author

No, the cause isn't related to bot leaving and rejoining a guild (at least not for me).

I don't know of any way of reproducing this. It looks like it happens at random. I run the bot continuously for a week until it's updated and restarted, and when I check the logs for previous week this comes up in the logs. I don't see any specific pattern, so I am unable to reproduce it.

@iamtraction
Copy link
Author

dc92582 probably fixed it as I haven't encountered this issue after updating to discord.js v11.3.2. So, I'm closing this issue. Thanks for the fix!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants