Repository: Pycord-Development/pycord

Issue:
AttributeError: module 'discord.ext' has no attribute 'bridge'
### Summary

This error occurs when attempting to load one of my cogs.

### Reproduction Steps

I have no idea what causes this. I do not use whatever 'bridge' is. Seems to be something slash command related.

### Minimal Reproducible Code

_No response_

### Expected Results

The cog to load.

### Actual Results

This stack trace
```py
Traceback (most recent call last):
  File "/home/crafter/.pyenv/versions/3.9.7/lib/python3.9/site-packages/discord/cog.py", line 715, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
AttributeError: module 'discord.ext' has no attribute 'bridge'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/crafter/.pyenv/versions/3.9.7/lib/python3.9/site-packages/jishaku/features/management.py", line 56, in jsk_load
    await discord.utils.maybe_coroutine(method, extension)
discord.errors.ExtensionFailed: Extension 'cogs.moderation' raised an error: AttributeError: module 'discord.ext' has no attribute 'bridge'
```

It's not an issue with Jishaku by the way. It happens on startup.

### Intents

discord.Intents.all()

### System Information
```
- Python v3.9.7-final
- py-cord v2.0.0-beta
    - py-cord pkg_resources: v2.0.0b7
- aiohttp v3.8.0
- system info: Linux 5.10.0-9-cloud-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30)
```

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.

### Additional Context

This works on my local machine with the same code and version of Pycord, no idea why.


Discussion:
I seem to have narrowed it down to [this commit](https://github.com/Pycord-Development/pycord/commit/a30f76dcf180196f5b17919460748679c8b6107f).
Please provide the code from your cog that is causing the issue.
I have idea what code could be causing it. The stack trace doesn't tell me.
This seems to be a error on my side as well.
> I have idea what code could be causing it. The stack trace doesn't tell me.

You mentioned it happens when loading one of your cogs. Post that cog's code. 
I'm getting this error too and for me it's caused by this line:
`from discord.ext.pages import Paginator`

Here's the exception i get running a blank python script with just this line:
```py
Traceback (most recent call last):
  File "/home/kiko/Projects/example.py", line 1, in <module>
    from discord.ext.pages import Paginator
  File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/__init__.py", line 10, in <module>
    from .pagination import *
  File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/pagination.py", line 270, in <module>
    class Paginator(discord.ui.View):
  File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/pagination.py", line 909, in Paginator
    interaction: Union[discord.Interaction, discord.ext.bridge.BridgeContext],
AttributeError: module 'discord.ext' has no attribute 'bridge'```
> `from discord.ext.pages import Paginator`

I cannot reproduce the issue when using this line, or at all. Can you please ensure that you're on the latest `master` version of the library? 
> > `from discord.ext.pages import Paginator`
> 
> I cannot reproduce the issue when using this line, or at all. Can you please ensure that you're on the latest `master` version of the library? 

I installed pycord by using this command:
`pip install git+https://github.com/Pycord-Development/pycord.git`
> I'm getting this error too and for me it's caused by this line:
> 
> `from discord.ext.pages import Paginator`
> 
> 
> 
> Here's the exception i get running a blank python script with just this line:
> 
> ```py
> 
> Traceback (most recent call last):
> 
>   File "/home/kiko/Projects/example.py", line 1, in <module>
> 
>     from discord.ext.pages import Paginator
> 
>   File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/__init__.py", line 10, in <module>
> 
>     from .pagination import *
> 
>   File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/pagination.py", line 270, in <module>
> 
>     class Paginator(discord.ui.View):
> 
>   File "/home/kiko/.local/lib/python3.10/site-packages/discord/ext/pages/pagination.py", line 909, in Paginator
> 
>     interaction: Union[discord.Interaction, discord.ext.bridge.BridgeContext],
> 
> AttributeError: module 'discord.ext' has no attribute 'bridge'```

My cog contains that code. Seems to be the issue.
I think I found the culprit, working on a fix now. Workaround in the meantime is to add `from discord.ext import bridge` before the offending line.

Resolving patch:
diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py
--- a/discord/ext/pages/pagination.py
+++ b/discord/ext/pages/pagination.py
@@ -24,6 +24,7 @@
 from typing import Dict, List, Optional, Union
 
 import discord
+from discord.ext.bridge import BridgeContext
 from discord.ext.commands import Context
 
 __all__ = (
@@ -906,7 +907,7 @@ async def edit(
 
     async def respond(
         self,
-        interaction: Union[discord.Interaction, discord.ext.bridge.BridgeContext],
+        interaction: Union[discord.Interaction, BridgeContext],
         ephemeral: bool = False,
         target: Optional[discord.abc.Messageable] = None,
         target_message: str = "Paginator sent!",
@@ -915,7 +916,7 @@ async def respond(
 
         Parameters
         ------------
-        interaction: Union[:class:`discord.Interaction`, :class:`discord.ext.bridge.BridgeContext`]
+        interaction: Union[:class:`discord.Interaction`, :class:`BridgeContext`]
             The interaction or BridgeContext which invoked the paginator.
             If passing a BridgeContext object, you cannot make this an ephemeral paginator.
         ephemeral: :class:`bool`
@@ -937,7 +938,7 @@ async def respond(
             The :class:`~discord.Message` or :class:`~discord.WebhookMessage` that was sent with the paginator.
         """
 
-        if not isinstance(interaction, (discord.Interaction, discord.ext.bridge.BridgeContext)):
+        if not isinstance(interaction, (discord.Interaction, BridgeContext)):
             raise TypeError(f"expected Interaction or BridgeContext, not {interaction.__class__!r}")
 
         if target is not None and not isinstance(target, discord.abc.Messageable):


Test patch: