python - Discord.py 从其他文件导入命令总是失败
问题描述
我尝试让我的机器人更清洁,我不想使用 COGS,所以我使用文件拆分,但是如果我尝试导入 Py 文件,它可以导入,但它输出一个错误,它找不到名为命令的东西
所以,这是 Main.py 中的代码
import discord
from discord import Webhook, AsyncWebhookAdapter
from discord.ext import commands, tasks
from discord.ext.commands import Bot
client = commands.Bot(command_prefix = ">", intents=discord.Intents().all())
@commands.command()
async def test1(self, ctx, choice: int):
await ctx.message.delete()
await ctx.send("This is a Command in the Main py!")
from me import *
client.run("I like ya Cut G", bot=True)
这段代码在 me.py
@commands.command()
async def suggest(self, ctx, *, message):
await ctx.send(message)
我总是得到这个错误!
Traceback (most recent call last):
File "C:\Users\lequi\Desktop\main.py", line 13, in <module>
from me import *
File "C:\Users\lequi\Desktop\me.py", line 1, in <module>
@commands.command()
NameError: name 'commands' is not defined
解决方案
首先,您从该client.run
行发布了您的不和谐客户端令牌。如果我是你,我会尽快编辑并更改机器人令牌。除了您之外,没有人应该有权访问它。
推荐阅读
- javascript - 尝试在 guillotine.js 中显示具有动态宽度和高度的图像。在固定宽度和高度下工作正常
- gremlin - Python Gremlin 中的顶点未更新
- python - pyautogui 在下拉菜单中定位某些文本
- android - Android Studio - 如何在 Kotlin 中执行 doubleClick?
- asp.net-mvc - 如何将 bundleConfig.cs 从项目 asp.net mvc 迁移到 asp.net core?
- javascript - NGINX proxy_pass http://localhost:9999/ 未找到
- python - Tensorflow One Hot Encoding - 找不到节点的有效设备
- php - 如何使用php获取数组中文件的扩展名
- android - 在图标顶部显示工具提示箭头,该箭头是对齐 TextView 中文本的结尾
- ios - 是否可以通过 IPA 文件永久安装应用程序?