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

Discord update broke functionality? #454

Open
Treebeardz opened this issue Feb 14, 2023 · 5 comments
Open

Discord update broke functionality? #454

Treebeardz opened this issue Feb 14, 2023 · 5 comments

Comments

@Treebeardz
Copy link

Treebeardz commented Feb 14, 2023

Using just this code

bot = discum.Client(token=CLIENT_TOKEN, log=False)

@bot.gateway.command
def databot(resp):
    if resp.event.message:
      pMessage = resp.parsed.auto()
      print(pMessage)

bot.gateway.run(auto_reconnect=True)

Some servers the client/user(CLIENT_TOKEN) are in do not trigger an event message. Its like no message was sent. Nothing prints as if there are no messages being sent unless its outside of this community server. In this scenario the client/user is apart of one community server and for testing purposes I made another server with a different/new client/user account. When I send a message in this newly created server it does trigger a message event.

Is this something that broke during an update or is this other community server some how hiding its messages and activity from user/self bots?

@reconSuave
Copy link

reconSuave commented Feb 20, 2023

Discum has been working fine for me, you may just need to send opcode 14 to those guilds, discum doesn't send them by default.

Try this:

bot = discum.Client(token=CLIENT_TOKEN, log=False)

@bot.gateway.command
def subTest(resp):
    if resp.event.ready_supplemental:
        bot.gateway.subscribeToGuildEvents(wait=1)
    if resp.event.message:
        pMessage = resp.parsed.auto()
        print(pMessage)

bot.gateway.run(auto_reconnect=True)

It can take a few tries for it to work, also you can try setting log to file and console to false, then respond to ready_supplemental with only the subscribe command above (don't parse messages). Sometimes parsing can break the pipe (I think just because discum is synchronous and Python is very slow).

@Treebeardz
Copy link
Author

Discum has been working fine for me, you may just need to send opcode 14 to those guilds, discum doesn't send them by default.

Try this:

bot = discum.Client(token=CLIENT_TOKEN, log=False)

@bot.gateway.command
def subTest(resp):
    if resp.event.ready_supplemental:
        bot.gateway.subscribeToGuildEvents(wait=1)
    if resp.event.message:
        pMessage = resp.parsed.auto()
        print(pMessage)

bot.gateway.run(auto_reconnect=True)

It can take a few tries for it to work, also you can try setting log to file and console to false, then respond to ready_supplemental with only the subscribe command above (don't parse messages). Sometimes parsing can break the pipe (I think just because discum is synchronous and Python is very slow).

I get this when running the version you suggested.

Exception ignored in thread started by: <bound method GatewayServer._response_loop of <discum.gateway.gateway.GatewayServer object at 0x7f2e6aeba180>>
Traceback (most recent call last):
File "/home/runner/Discord-SCUM/discum/gateway/gateway.py", line 299, in _response_loop
func(resp)
File "main.py", line 47, in subTest
bot.gateway.subscribeToGuildEvents(wait=1)
File "/home/runner/Discord-SCUM/discum/gateway/gateway.py", line 490, in subscribeToGuildEvents
imports.GuildCombo(self).subscribeToGuildEvents(onlyLarge, wait)
File "/home/runner/Discord-SCUM/discum/gateway/guild/combo.py", line 179, in subscribeToGuildEvents
findChannel = self.findVisibleChannels(guildID, types="all", findFirst=True)
File "/home/runner/Discord-SCUM/discum/gateway/guild/combo.py", line 156, in findVisibleChannels
permissions = Permissions.calculatePermissions(s.user['id'], guildID, s.guild(guildID).owner, s.guild(guildID).roles, s.guild(guildID).me['roles'], channel["permission_overwrites"])
File "/home/runner/Discord-SCUM/discum/gateway/session.py", line 256, in owner
return Session.settings_ready['guilds'][self.guildID]['owner_id'] #returns type int
KeyError: 'owner_id'

@reconSuave
Copy link

Wrap bot.gateway.subscribeToGuildEvents in a try/except and just let that KeyError pass, I'm pretty sure it will still send the opcode.

I think it's actually already been sent when that error is thrown and you should still be able to run the gateway without that key set initially because I think running the gateway sets it, but I'm not 100% sure, if I get some time I'll see if I can figure out what's going on, but try something like this:

bot = discum.Client(token=CLIENT_TOKEN, log=False)

@bot.gateway.command
def subTest(resp):
    if resp.event.ready_supplemental:
        try:bot.gateway.subscribeToGuildEvents(wait=1)
        except:pass
    if resp.event.message:
        pMessage = resp.parsed.auto()
        print(pMessage)

bot.gateway.run(auto_reconnect=True)

I haven't actually been able to recreate that error you're getting, but from the traceback you posted it seems to be the same type of situation that's happening with the other KeyError problems like with the guilds key, here the owner_id key isn't set because there's some event that sets it and that's not happening or some function that needs to be called first but isn't, probably the fix is to just set it initially to a placeholder value like None or empty dict. I'm curious to know what's actually going on so hopefully I can devote some time to it soon and I'll update if I figure out what's actually causing this.

@Treebeardz
Copy link
Author

I should mention I'm using Replit and used their "import github" option to pull the DISCUM source. They have a package that needs to be installed as its a requirement for DISCUM. The Replit package is called "websocket-client2". Without this pkg I get this error when attempting to run the source.

Traceback (most recent call last):
File "main.py", line 5, in
bot = discum.Client(token=NEVERLAND_TOKEN, log=False)
File "/home/runner/Discord-SCUM/discum/discum.py", line 109, in init
self.gateway = GatewayServer(self.websocketurl, self.__user_token, self.__super_properties, self.s, self.discord, self.log)
File "/home/runner/Discord-SCUM/discum/gateway/gateway.py", line 125, in init
self.ws = self._get_ws_app(websocketurl)
File "/home/runner/Discord-SCUM/discum/gateway/gateway.py", line 163, in _get_ws_app
ws = websocket.WebSocketApp(websocketurl,
AttributeError: module 'websocket' has no attribute 'WebSocketApp'. Did you mean: 'WebSocket'?

Not sure if this is related to this issue or causing it at all.

Furthermore If I run

bot.gateway.fetchMembers(guild_id, channel_id) for the guild in question the messages come through for a while but then they stop after some time.

I wrapped the try/except and its working just fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Treebeardz @reconSuave and others