Discord Python重写-反应帮助Cog

如何解决Discord Python重写-反应帮助Cog

我试图提供依赖于反应的帮助,我得到了这段代码

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,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))

但是它不起作用,我得到一个错误。

错误是:

回溯(最近通话最近):文件 “ C:\ Users \ PC \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ discord \ ext \ commands \ bot.py”, _load_from_module_spec中的第607行 spec.loader.exec_module(lib)文件“”,在exec_module文件中的第779行 get_code文件中的“”行916, source_to_code中的“”行846 在第219行的文件“”中 _call_with_frames_removed文件“ C:\ Users \ PC \ Desktop \ Code \ Waifu Bot \ cogs \ testhelp.py”,第22行 尝试: ^ IndentationError:unindent与任何外部缩进级别都不匹配

上述异常是以下异常的直接原因:

回溯(最近通话最近):文件 “ C:\ Users \ PC \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ discord \ client.py”, _run_event中的第312行 等待coro(* args,** kwargs)文件“ C:\ Users \ PC \ Desktop \ Code \ Waifu Bot \ setup.py”,行95,在on_ready中 在on_ready中提高文件“ 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(规格,名称)文件“ C:\ Users \ PC \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ discord \ ext \ commands \ bot.py”, _load_from_module_spec中的第610行 引发错误。来自discord.ext.commands.errors.ExtensionFailed:ExtensionFailed(key,e):扩展名'cogs.testhelp' 引发错误:IndentationError:unindent与任何外部不匹配 缩进级别(testhelp.py,第22行)

解决方法

这只是一个简单的缩进错误(位于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,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:为避免缩进错误,请避免在代码行之后跳过行,这将更容易检测到这些错误,并且您的代码将更易于理解^^

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-