Comments (12)
Cannot reproduce. Can you confirm that this still occurs?
from pycord.
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.
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.
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.
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.
@BobDotCom should take a look at this.
from pycord.
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.
Can reproduce it sharded and non sharded.
from pycord.
from pycord.
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.
from pycord.
@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)
- BridgeOption converts discord.Member wrong with ext command
- Unclosed client session, Unclosed connector HOT 3
- deprecate and replace with interaction_metadata HOT 5
- authorizing_integration_owners HOT 1
- Temporary disable slash_command in py-cord HOT 4
- Guild.search_members bug
- AttributeError: 'FFmpegPCMAudio' object has no attribute '_process' HOT 2
- Interaction Error on Shard Reconnection HOT 4
- Constant Shard Reconnection and ConnectionClosed Errors with AutoShardedBot HOT 1
- string returned for slash commands when using `Option/input_type` HOT 1
- Subcommand groups not showing up in the Slash Command channel HOT 4
- Slash commands interaction response doesnt give message HOT 1
- Error importing SlashCommandGroup, Page, ext.pages HOT 3
- audit_logs not fetching more than 100 logs HOT 4
- Paginator error upon failed interaction
- DeprecationWarning for BridgeOption raised at module level
- v2.7: Remove backwards support for Option in bridge commands.
- Add description attribute to ClientUser HOT 1
- Unclear exception when command is run without first creating bot in server HOT 1
- sync_commands doesnt raise error HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycord.