dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
683 stars 162 forks source link

Running `channel.slash_commands()` yields infinitely #345

Closed Iinksafe closed 2 years ago

Iinksafe commented 2 years ago

Summary

Running channel.slash_commands() yields Slash Commands infinitely.

Reproduction Steps

  1. Get a channel using Client.get_channel(<Snowflake id>)
  2. As soon as you get the channel, request Slash Commands using TextChannel.slash_commands()
  3. The function will yield infinitely with the (same) Slash Commands and won't finish.

Code

# This is the example in the documentation. Click the link below to go to the code example:
# https://discordpy-self.readthedocs.io/en/latest/api.html#discord.TextChannel.slash_commands

async for command in channel.slash_commands():
    print(command.name)

Expected Results

Return the Slash Commands and exit the async generator once it has finished.

Actual Results

The function returns the Slash Commands but yields infinitely.

System Information

- Python v3.8.12-final
- discord.py-self v2.0.0-alpha
    - discord.py-self pkg_resources: v2.0.0a2
- aiohttp v3.7.4.post0
- system info: Linux 5.15.0-1013-gcp #18~20.04.1-Ubuntu SMP Sun Jul 3 08:20:07 UTC 2022

Checklist

Additional Information

Example of what it yields (let's say we only have 5 Slash Commands with 3 bots):

-> help
-> ping
-> purge
-> kick
-> ban # Function should exit async generator here (remember, we only have 5 Slash Commands)
-> help
-> ping
-> purge
-> kick
-> ban
... # "..." means that it'll yield the same Slash Commands over and over (infinitely)
Iinksafe commented 2 years ago

Screenshot: imagen

adrianaryaputra commented 2 years ago

I've tried this, and it may be caused by the cursor not working on abc.py in function slash_command().

i tried to query 50 slash commands with

[ command async for command in message.channel.slash_commands(limit = 50) ]

which yield :

 [
               <SlashCommand id=1011560371267579943 name='8ball' options=1>,
               <SlashCommand id=1011560371041095693 name='achievements'>,
               <SlashCommand id=1011560371041095694 name='advancements' children=4>,
               <SlashCommand id=1011560371041095695 name='adventure'>,
               <SlashCommand id=1011560370864930852 name='alert'>,
               <SlashCommand id=1011560371309510699 name='animals' options=1>,
               <SlashCommand id=1011560370994954287 name='audit'>,
               <SlashCommand id=1011560371041095696 name='badges'>,
               <SlashCommand id=1011560371041095697 name='balance' options=1>,
               <SlashCommand id=1011560371041095698 name='bankrob' options=1>,
               <SlashCommand id=1011560371041095699 name='beg'>,
               <SlashCommand id=1011560371078832199 name='blackjack' options=1>,
               <SlashCommand id=1011560370994954288 name='block' children=3>,
               <SlashCommand id=1011560371078832200 name='bundles' children=2>,
               <SlashCommand id=1011560370864930854 name='buy' options=3>,
               <SlashCommand id=1011560370948800551 name='clap' options=1>,
               <SlashCommand id=1011560370864930855 name='compare' options=1>,
               <SlashCommand id=1011560371078832201 name='craft'>,
               <SlashCommand id=1011560371078832202 name='crime'>,
               <SlashCommand id=1011560371078832203 name='currencylog'>,
               <SlashCommand id=1011560370864930856 name='daily'>,
               <SlashCommand id=1011560370911072256 name='deposit' options=1>,
               <SlashCommand id=1011560371078832204 name='dig'>,
               <SlashCommand id=1011560371041095690 name='donor' children=2>,
               <SlashCommand id=1011560371078832205 name='drops'>,
               <SlashCommand id=1011560371267579943 name='8ball' options=1>,
               <SlashCommand id=1011560371041095693 name='achievements'>,
               <SlashCommand id=1011560371041095694 name='advancements' children=4>,
               <SlashCommand id=1011560371041095695 name='adventure'>,
               <SlashCommand id=1011560370864930852 name='alert'>,
               <SlashCommand id=1011560371309510699 name='animals' options=1>,
               <SlashCommand id=1011560370994954287 name='audit'>,
               <SlashCommand id=1011560371041095696 name='badges'>,
               <SlashCommand id=1011560371041095697 name='balance' options=1>,
               <SlashCommand id=1011560371041095698 name='bankrob' options=1>,
               <SlashCommand id=1011560371041095699 name='beg'>,
               <SlashCommand id=1011560371078832199 name='blackjack' options=1>,
               <SlashCommand id=1011560370994954288 name='block' children=3>,
               <SlashCommand id=1011560371078832200 name='bundles' children=2>,
               <SlashCommand id=1011560370864930854 name='buy' options=3>,
               <SlashCommand id=1011560370948800551 name='clap' options=1>,
               <SlashCommand id=1011560370864930855 name='compare' options=1>,
               <SlashCommand id=1011560371078832201 name='craft'>,
               <SlashCommand id=1011560371078832202 name='crime'>,
               <SlashCommand id=1011560371078832203 name='currencylog'>,
               <SlashCommand id=1011560370864930856 name='daily'>,
               <SlashCommand id=1011560370911072256 name='deposit' options=1>,
               <SlashCommand id=1011560371078832204 name='dig'>,
               <SlashCommand id=1011560371041095690 name='donor' children=2>,
               <SlashCommand id=1011560371078832205 name='drops'>
]

you can see that the slashes command loop after the 25th list, which is exactly what abc.py on line 1821 hard coded as max retrieve.

# abc.py : line 1819 - 1823

while True:
            cursor = MISSING
            retrieve = min(25 if limit is None else limit, 25)
            if retrieve < 1 or cursor is None:
                return
adrianaryaputra commented 2 years ago

the only workaround, for now, is to do a separate fetch for each application, which has a greater limit.

dolfies commented 2 years ago

This should be fixed.