Giter Club home page Giter Club logo

Comments (12)

BobDotCom avatar BobDotCom commented on July 22, 2024

Screen Shot 2021-09-10 at 10 33 52 AM
Cannot reproduce. Can you confirm that this still occurs?

from pycord.

Miolus avatar Miolus commented on July 22, 2024

Can still reproduce. Maybe a caching issue? Just tried again, I can't reproduce it with my 3-guilds bot, but with a 800-guilds bot.

from pycord.

BobDotCom avatar BobDotCom commented on July 22, 2024

It runs fetch_guilds and then adds all the guild ids to the dict containing an empty list for each

async for guild in self.fetch_guilds(limit=None):
    update_guild_commands[guild.id] = []

After this, it processes the guild_ids passed into all of the commands

    for command in [cmd for cmd in self.pending_application_commands if cmd.guild_ids is not None]:
        as_dict = command.to_dict()
        for guild_id in command.guild_ids:
            to_update = update_guild_commands[guild_id]

It appears this error could occur if a guild_id passed into one of the commands doesn't actually belong to a guild that the bot is in, could you check if that is true? A simple fix to this would be changing

to_update = update_guild_commands[guild_id]

to

to_update = update_guild_commands.get(guild_id, [])

but that would just be avoiding a bigger issue so I don't think it should be used.

from pycord.

Miolus avatar Miolus commented on July 22, 2024

I've tried it again in logging debug mode double checking the guild id, the guild was sent in the guild_create events on startup.

from pycord.

lukenamop avatar lukenamop commented on July 22, 2024

Hello, I am having this issue as well as I am trying to test slash commands in my bot which is in 6.1k servers:

# testing slash commands
@client.slash_command(guild_ids=[667412571728379940])
async def new(
	ctx,
	name: Option(str, "Enter your name"),
	gender: Option(str, "Choose your gender", choices=["Male", "Female", "Other"]),
	age: Option(int, "Enter your age", required=False, default=18),
):
	await ctx.send(f'Hello {name}, it looks like you are {age} years old and {gender}.')
	return
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/discord/client.py", line 351, in _run_event
    await coro(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/discord/bot.py", line 370, in on_connect
    await self.register_commands()
  File "/usr/local/lib/python3.8/dist-packages/discord/bot.py", line 191, in register_commands
    to_update = update_guild_commands[guild_id]
KeyError: 667412571728379940

from pycord.

Grace-codes avatar Grace-codes commented on July 22, 2024

@BobDotCom should take a look at this.

from pycord.

BobDotCom avatar BobDotCom commented on July 22, 2024

I believe this may be an issue with the optimization of guild commands at the moment for larger bots in our library. At the time being I would recommend not using guild commands for large bots until this issue is fixed.

It's also possible it could be happening only on sharded bots, but i haven't explored this possibility yet. Could @lukenamop and @Miolus confirm that they were using sharded bots?

from pycord.

Miolus avatar Miolus commented on July 22, 2024

Can reproduce it sharded and non sharded.

from pycord.

lukenamop avatar lukenamop commented on July 22, 2024

from pycord.

BobDotCom avatar BobDotCom commented on July 22, 2024

Try adding

@bot.event
async def on_ready():
    print(bot.guilds)
    await bot.register_commands()

See if the server you're looking for is there. (You can use a different way to check, but do it in on_ready and before register_commands). It might be an issue with guilds not being cached.

from pycord.

lukenamop avatar lukenamop commented on July 22, 2024

from pycord.

lukenamop avatar lukenamop commented on July 22, 2024

@BobDotCom first I added the check (your print(bot.guilds), but I just made it iterate through the list of guilds and print a confirmation if my guild was found. on_ready() waited until all 8 shards were loaded and then ran, confirming that my target guild was found. Then I added the await bot.register_commands() after my check and un-commented the slash command and tried again. I received the error as soon as I started to execute the file, which to me means the bot tried to register the command before I explicitly called await bot.register_commands() which means it happened before on_ready() which is why the guild is not found.

TL;DR: @client.slash_command(guild_ids=[]) seems to be attempting to register commands as soon as the code is executed, rather than adding a flag to be registered after the bot is ready. As such, the guild doesn't exist in the bot's cache, and it errors out and breaks.

from pycord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.