Giter VIP home page Giter VIP logo

discord-ui's People

Contributors

brotherelric avatar codacy-badger avatar deepsourcebot avatar kvsxxx avatar polytree18 avatar redstonezockt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

discord-ui's Issues

ctx.author.send() gives a 404 "Unknown Channel" error

When using discord-ui, any attempt to perform an await ctx.author.send(...) results in the following error:

File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/override.py", line 50, in send
    r = await self._state.http.request(route, json=payload)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/http.py", line 250, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10003): Unknown Channel

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10003): Unknown Channel

Currently, I'm working around it by manually creating a DM channel, but it's an ugly kludge.

Replies are broken

Performing a simple await ctx.reply() does not actually reply. The message is sent without tying it to the appropriate message/context.

The same is true for await ctx.message.reply().

AttributeError when creating extension instance inside custom Bot class

When creating the extension as part of a custom bot class, you get an AttributeError.
I'm using Python 3.9.6, discord.py version 1.7.3 and discord-ui version 3.1.0.

Traceback (most recent call last):
  File "main.py", line 10, in <module>
    bot = CustomBot(command_prefix="!")
  File "main.py", line 8, in __init__
    self.ui = UI(self)
  File "discord_ui/client.py", line 1038, in __init__
    self.components = Components(client, auto_defer=auto_defer)
  File "discord_ui/client.py", line 810, in __init__
    elif discord.__version.startswith("1"):
AttributeError: module 'discord' has no attribute '_Components__version'

(I removed unnecessary parts of the paths)

Here's the code:

from discord.ext import commands
from discord_ui import *

class CustomBot(commands.Bot):
    def __init__(self, **options):
        super().__init__(**options)
        self.ui = UI(self)

bot = CustomBot(command_prefix="!")
bot.run("token here")

The documentation suggests that it has to be a commands.Bot, but I don't see how this would break it.
Additionally, this only started happening once I updated to 3.1.0.

Guild command can only be used once

(Please point out any mistakes, if I get too confused.)
I created a guild-only slash command, as follows:

bs = Slash(bot)
...
@bs.command(name= "test",
            description= "Foo bar", guild_ids= [880686520678371369],
            default_permission= False,
            guild_permissions= {880686520678371369: ui.SlashPermission(allowed= {ui.SlashPermission.USER: [687474789342117900]})}
)
async def tester(ctx):
    await ctx.respond("Test")
# 687474789342117900 is my user ID

I invoked this slash command. Immediately after that, the command gets removed from the list of other commands. All other commands continued to work, so I believe it is not a fatal bug. I tried looking into the module's code but I cannot find anything - I think it might be the bot wrongly deleting the command?

Lacking support for split files

Motivation

The official discord.py library supports loading extension commands from other files, so I think it is a good idea for discord_ui to have it as well. Otherwise, large bots can easily get to tens of thousands of lines in a single file.

Reference code

To put this conveniently, here is the bot.load_extension() method definition:

# In the Bot class
def load_extension(
        self,
        name: str,
        *,
        package: Optional[str] = None,
        extras: Optional[Dict[str, Any]] = None
    ) -> None:
            name = self._resolve_name(name, package)
            if name in self.__extensions:
                raise errors.ExtensionAlreadyLoaded(name)
        
            spec = importlib.util.find_spec(name)
            if spec is None:
                raise errors.ExtensionNotFound(name)
        
            self._load_from_module_spec(spec, name, extras=extras)

Cannot send files alongside a message

When overridden, ctx.send does raises an exception if you pass in a file or files kwarg, while the regular discord.py ctx.send does not.
After peeking at the source, it seems that the jsonifyMessage function wants the discord.Attachment class - which is the class for an attachment on an already existing message. It also tries to put it in the attachments field of the payload object, which the Discord API does not support (according to https://discord.com/developers/docs/resources/channel#create-message-jsonform-params)

Ninja mode gives 404 Not Found

Responding to a select menu interaction using ninja mode gives a 404 Not Found, with error code 10062 (Unknown interaction). I tested with sending a message, and it works. (I'm receiving the event through a @commands.Cog.listener("on_menu_select") decorated function, since I couldn't find a way to use the other ways with cogs; actually, better support for cogs would be great). Sorry for not providing an example, I'm in a hurry right now.

Unable to remove embeds from a message

Per the dpy docs, await msg.edit(embed=None) is supposed to remove an embed from a message. However, I receive the following error:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/client.py", line 257, in _on_response
    await x.invoke(context, **options)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/cogs.py", line 98, in invoke
    raise ex
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/cogs.py", line 93, in invoke
    await self.callback(self.cog, ctx, *args, **kwargs)
  File "/Users/tiltowait/Developer/inconnu/interface/characters.py", line 104, in delete_character
    await inconnu.delete.prompt(ctx, character)
  File "/Users/tiltowait/Developer/inconnu/inconnu/delete.py", line 28, in prompt
    await msg.edit(embed=None)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/receive.py", line 668, in edit
    self._update(await self._state.http.request(r, json=jsonifyMessage(*args, **fields)))
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/http.py", line 70, in jsonifyMessage
    raise WrongType("embeds", embeds, 'list[discord.Embed]')
discord_ui.errors.WrongType: 'embeds' must be of type list[discord.Embed], not <class 'list'>

Out of curiosity, I tried embeds=None but got a different error:

Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/client.py", line 257, in _on_response
    await x.invoke(context, **options)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/cogs.py", line 98, in invoke
    raise ex
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/cogs.py", line 93, in invoke
    await self.callback(self.cog, ctx, *args, **kwargs)
  File "/Users/tiltowait/Developer/inconnu/interface/characters.py", line 104, in delete_character
    await inconnu.delete.prompt(ctx, character)
  File "/Users/tiltowait/Developer/inconnu/inconnu/delete.py", line 28, in prompt
    await msg.edit(embeds=None)
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/receive.py", line 668, in edit
    self._update(await self._state.http.request(r, json=jsonifyMessage(*args, **fields)))
  File "/opt/homebrew/lib/python3.9/site-packages/discord_ui/http.py", line 69, in jsonifyMessage
    if not all(isinstance(x, discord.Embed) for x in embeds):
TypeError: 'NoneType' object is not iterable

Nextcord does not work with discord-ui

Hey, I tried today to rewrite my Discord bot to Nextcord but somehow I can't because discord-ui requires discord.py and the lib of Discord-UI doesn't support Nextcord, is there any way to fix this?

Before the question comes up, I am using discord-ui version 5.1.5

Cannot send embeds in preview release

Error message: discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
Posting here for the sake of organization.

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.