Reputation: 388
I'm trying to make a help that relies on reactions, I got this code
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))
but it didn't work, I get an error.
The error is:
Traceback (most recent call last): File "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 607, in _load_from_module_spec spec.loader.exec_module(lib) File "", line 779, in exec_module File "", line 916, in get_code File "", line 846, in source_to_code File "", line 219, in _call_with_frames_removed File "C:\Users\PC\Desktop\Code\Waifu Bot\cogs\testhelp.py", line 22 try: ^ IndentationError: unindent does not match any outer indentation level
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event await coro(*args, **kwargs) File "C:\Users\PC\Desktop\Code\Waifu Bot\setup.py", line 95, in on_ready raise e File "C:\Users\PC\Desktop\Code\Waifu Bot\setup.py", line 92, in on_ready client.load_extension(cog) File "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 664, in load_extension self._load_from_module_spec(spec, name) File "C:\Users\PC\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 610, in _load_from_module_spec raise errors.ExtensionFailed(key, e) from e discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.testhelp' raised an error: IndentationError: unindent does not match any outer indentation level (testhelp.py, line 22)
Upvotes: 0
Views: 1515
Reputation: 3994
This is just a simple indentation error (at try...except
):
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: #Indent error here, delete one tabulation
await ctx.send("Timed out") #Also Delete one tabulation here
@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))
PS: To avoid indent error, avoid to skip a line after a code line, it will be easier to detect those errors and your code will be more understandable ^^
Upvotes: 0