我在这里比较困惑,在试图研究答案时,我似乎找不到任何对我有意义的东西。我已经创建了一个有5个齿轮的不和谐机器人,在每个机器人中我import discord, os, and from discord.ext import commands in各种其他齿轮,我import其他模块,如random,视情况而定,但这是三个常见的模块。
问题是,在每个模块中,import discord都是灰色的(PyCharm集成开发环境),这表明它从未被使用过。尽管如此,我的机器人运行得很好。我似乎不能使用像wait_for()命令这样的东西,我猜是因为它在discord模块中?我没有正确地设置来使用它吗?
我将发布初始启动模块和另一个模块的一小段代码,而不是list模块。如果您需要更多信息,请让我知道。
初始启动:
import discord
import os
from discord.ext import commands
token = open("token.txt", "r").read()
client = commands.Bot(command_prefix = '!')
@client.command()
async def load(ctx, extension):
client.load_extension("cogs." + extension)
@client.command()
async def unload(ctx, extension):
client.unload_extension("cogs." + extension)
for filename in os.listdir("./cogs"):
if filename.endswith('.py'):
client.load_extension("cogs." + filename[:-3])
client.run(token)另一个模块:
import discord
from discord.ext import commands
import os
import json
from pathlib import Path
class Sheet(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
@commands.dm_only()
async def viewchar(self, ctx):
#Snipped code here to make it shorter.
pass
@viewchar.error
async def stats_error(self, ctx, error):
if isinstance(error, commands.PrivateMessageOnly):
await ctx.send("You're an idiot, now everyone knows. Why would you want to display your character sheet "
"in a public room? PM me with the command.")
else:
raise error
def setup(client):
client.add_cog(Sheet(client))发布于 2019-07-15 21:46:55
这只意味着您的代码不会在任何地方直接引用discord模块。您可以通过commands模块获取所有内容。
您可以在不破坏任何内容的情况下从代码中删除import discord,因为依赖它的代码仍然会在幕后导入和使用它。
https://stackoverflow.com/questions/57024502
复制相似问题