Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.71k stars 459 forks source link

Unclear exception when command is run without first creating bot in server #2455

Closed telecter closed 3 months ago

telecter commented 3 months ago

Summary

When a client runs an application command without there being a bot in the server, Pycord crashes with an unclear exception.

Reproduction Steps

  1. Create a Discord app
  2. Make sure to not select the "bot" install setting, and install the app on a server
  3. Create a basic Python script using Pycord as shown below
  4. Run the command created in the below script in Discord
  5. Observe any errors

Minimal Reproducible Code

import discord

bot = discord.Bot()

@bot.slash_command()
async def testcommand(ctx: discord.ApplicationContext):
    await ctx.respond("test")

bot.run("<bot token>")

Expected Results

I expected a clear error (inheriting from DiscordException at least) as to why the command failed.

Actual Results

A NameError lacking any context as to why the error occurred is shown.

Full Traceback:


  File "<virtual env>/lib/python3.12/site-packages/discord/client.py", line 766, in run
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<virtual env>/lib/python3.12/site-packages/discord/client.py", line 745, in runner
    await self.start(*args, **kwargs)
  File "<virtual env>/lib/python3.12/site-packages/discord/client.py", line 709, in start
    await self.connect(reconnect=reconnect)
  File "<virtual env>/lib/python3.12/site-packages/discord/client.py", line 601, in connect
    await self.ws.poll_event()
  File "<virtual env>/lib/python3.12/site-packages/discord/gateway.py", line 605, in poll_event
    await self.received_message(msg.data)
  File "<virtual env>/lib/python3.12/site-packages/discord/gateway.py", line 555, in received_message
    func(data)
  File "<virtual env>/lib/python3.12/site-packages/discord/state.py", line 818, in parse_interaction_create
    interaction = Interaction(data=data, state=self)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<virtual env>/lib/python3.12/site-packages/discord/interactions.py", line 171, in __init__
    self._from_data(data)
  File "<virtual env>/lib/python3.12/site-packages/discord/interactions.py", line 201, in _from_data
    self._guild = Guild(data=self._guild_data, state=self)
                  ^^^^^
NameError: name 'Guild' is not defined. Did you mean: 'guild'?

Intents

3243773

System Information

macOS 14.5 (Darwin 23.5.0, arm64) Python 3.12.3

Checklist

Additional Context

No response

NeloBlivion commented 3 months ago

This was already fixed on master branch.