[英]Printing discord.Interaction throwing a error discord.py
Discord 最近添加了与按钮交互的按钮,我使用python3 -m pip install -U discord.py-message-components
安装了它们,如discord.py 按钮中给出的。
现在,当我尝试打印 Intercation 对象并收到此错误时
Ignoring exception in command test_command:
Traceback (most recent call last):
File "/home/ibrahim/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 245, in test_command
print(interaction, button)
File "/home/ibrahim/.local/lib/python3.8/site-packages/discord/interactions.py", line 96, in __repr__
return f'<Interaction {", ".join(["%s=%s" % (a, getattr(self, a)) for a in self.__slots__ if a[0] != "_"])}>'
AttributeError: 'Interaction' object has no attribute '__slots__'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ibrahim/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 1062, in invoke
await ctx.command.invoke(ctx)
File "/home/ibrahim/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/ibrahim/.local/lib/python3.8/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: AttributeError: 'Interaction' object has no attribute '__slots__'
这是我的代码
@commands.command(ignore_extra=True)
async def test_command(self, ctx, count:int):
new_button = Button(label="test_button", custom_id = "009")
message = await ctx.send("test", components = [[new_button]])
def check_button(i: discord.Interaction, button):
return i.author == ctx.author and i.message == message
interaction, button = await bot.wait_for('button_click', check=check_button)
print(interaction, button)
await interaction.edit(content=count)
这些是我进口的东西
import discord
from discord import Button, ButtonStyle, SelectMenu, SelectOption
from discord.ext import commands
from discord.ext.commands import check, Context, MemberConverter
我尝试过的事情:
from discord import Interaction
为什么会发生此错误,我该如何解决?
我认为,这是一个错误。 我看到它的源代码,它没有定义__slots__
。
在__init__
部分,它没有定义__slots__
。
在__repr__
部分,它在return
语句中插入了__slots__
。 因此,它引发了AttributeError
。
帮不了你。
您可以打印一些属性,例如作者、按钮标签、消息等……以打印一些信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.