Merubokkusu / Discord-S.C.U.M

A Discord API Wrapper for Userbots/Selfbots written in Python.
MIT License
588 stars 167 forks source link

Discord update broke functionality? #454

Open Treebeardz opened 1 year ago

Treebeardz commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

ImSoGodDamnCoolWowAAAA commented 3 months ago

I was receiving this issue as well. And I came up with a VERY janky solution that still allows you to use that event and not have to try except block it as this just causes you to loose Guild functionality. And that very janky solution is: Change:

return Session.settings_ready['guilds'][self.guildID]['owner_id'] #returns type int

to:

try:
    return Session.settings_ready['guilds'][self.guildID]['owner_id'] #returns type int
except KeyError:
    return 0

(In file sessions.py, line 256ish)

However the downside of this is that it can cause you to not be able to get the owner's id later on and you'd have to do it manually.