在cogs discord.py中使用不协调组件的按钮时面临错误


import discord
from discord.ext import commands
bot = discord.ext.commands.Bot(command_prefix = ";");
import random
from asyncio import TimeoutError
import subprocess
import sys
from discord_components import *
class GameCommands(commands.Cog):

def __init__(self, bot):
self.bot=bot
@commands.Cog.listener()
async def on_ready(self):
DiscordComponents(bot)
print('ready')
@commands.command() 
async def rps(self,ctx):
choices=['rock','paper','scissors']
bot_choise=random.choice(choices)
player_choise=""
yet= discord.Embed(title=f"{ctx.author.display_name}'s Rock Paper Scissors Game", description="Click On A Button", color=discord.Color.from_rgb(0, 208, 255))
won= discord.Embed(title=f"You Won! Le Hurray!", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(255, 213, 0))
lost= discord.Embed(title=f"You Lost! Sadge :(", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(102, 61, 69))
tie= discord.Embed(title=f"Hmm, A tie!", description=f"You and the bot both chose {bot_choise}", color=discord.Color.from_rgb(137, 49, 181))
out= discord.Embed(title=f"Timeout ", description=f"You didn't choose any option in time, Bruh!", color=discord.Color.from_rgb(43, 194, 146))
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
def check(res):
return ctx.author==res.user and res.channel==ctx.channel
try:
res= await self.bot.wait_for("button_click", check=check, timeout=15)
player_choise= res.component.label
if player_choise==bot_choise:
await m.edit(embed=tie, components=[])
if player_choise=="Paper" and bot_choise=="Rock":
await m.edit(embed=won, components=[])
if player_choise=="Scissors" and bot_choise=="Paper":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Scissors":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Paper":
await m.edit(embed=lost, components=[])
if player_choise=="Paper" and bot_choise=="Scissor":
await m.edit(embed=lost, components=[])
if player_choise=="Scissor" and bot_choise=="Rock":
await m.edit(embed=lost, components=[])
except TimeoutError:
await m.edit(embed=out, components=[])
def setup(bot):
bot.add_cog(GameCommands(bot))

我安装了discord组件,每当我运行命令时,我都会收到以下错误:

Ignoring exception in command rps:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/TheDuck/commands/games.py", line 37, in rps
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 46, in send_component_msg_prop
return await self.send_component_msg(ctxorchannel.channel, *args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 177, in send_component_msg
data = await self.bot.http.request(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
AttributeError: 'NoneType' object has no attribute 'request'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/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: 'NoneType' object has no attribute 'request'

我不知道是什么原因导致了这个错误。我试着在网上找到它,但没能找到。我想知道我可能犯了什么错误,或者这是一个错误。我看到几乎相同的代码在主文件上运行,没有任何问题。这是齿轮的问题还是我的代码错了?

虽然我不确定这是否是一个错误,但我认为最好使用Discord.py 2.0(目前在Alpha中(作为按钮,而不是第三方库。请记住,它可能是不稳定的,这也是你的选择。

相关内容

  • 没有找到相关文章

最新更新