【发布时间】:2021-01-02 01:40:39
【问题描述】:
我正在尝试提供依赖于反应的帮助,我得到了这个代码
import discord
from discord import Embed
from discord.ext import commands
class Helptest(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def helpreee(self, ctx):
await ctx.message.delete()
msg = await ctx.send("Eh idk just react")
await msg.add_reaction("⬅️")
await msg.add_reaction("➡️")
def check(reaction, user):
return user == ctx.message.author and str(reaction.emoji) in ['⬅️', '➡️']
try:
reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
if reaction.emoji == '➡️':
await ctx.message.delete()
await msg.reaction.clear()
msg1 = await msg.edit("Hewwo")
await msg1.add_reaction("⬅️")
reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
if reaction.emoji == '⬅️':
await msg.edit("Eh idk just react")
return
elif reaction.emoji == '⬅️':
await ctx.send("AAA")
except asyncio.TimeoutError:
await ctx.send("Timed out")
@helpreee.error
async def helpreee_error(self, ctx, error):
await ctx.send(error)
print(error)
raise error
def setup(client):
client.add_cog(Helptest(client))
但它不起作用,我收到一个错误。
错误是:
Traceback(最近一次调用最后一次):文件 "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", 第 607 行,在 _load_from_module_spec spec.loader.exec_module(lib) 文件“”,第 779 行,在 exec_module 文件中 "",第 916 行,在 get_code 文件中 "",第 846 行,在 source_to_code 中 文件“”,第 219 行,在 _call_with_frames_removed 文件“C:\Users\PC\Desktop\Code\Waifu Bot\cogs\testhelp.py”,第 22 行 尝试: ^ IndentationError: unindent 不匹配任何外部缩进级别
上述异常是以下异常的直接原因:
Traceback(最近一次调用最后一次):文件 "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", 第 312 行,在 _run_event await coro(*args, **kwargs) 文件“C:\Users\PC\Desktop\Code\Waifu Bot\setup.py”,第 95 行,on_ready 在 on_ready 中引发 e 文件“C:\Users\PC\Desktop\Code\Waifu Bot\setup.py”,第 92 行 client.load_extension(cog) 文件 "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", 第 664 行,在 load_extension 中 self._load_from_module_spec(spec, name) 文件 "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", 第 610 行,在 _load_from_module_spec 从 e discord.ext.commands.errors.ExtensionFailed 引发 errors.ExtensionFailed(key, e): Extension 'cogs.testhelp' 引发错误:IndentationError: unindent does not match any outer 缩进级别(testhelp.py,第 22 行)
【问题讨论】:
标签: discord discord.py discord.py-rewrite