【发布时间】:2019-11-23 06:09:28
【问题描述】:
我在这里比较困惑,在尝试研究答案时,我似乎找不到任何对我有意义的东西。我创建了一个包含 5 个 cog 的不和谐机器人,在每个 cog 中我 import discord, os, and from discord.ext import commands 在其他各种 cog 中我 import 其他模块,如 random 视情况而定,但这是三个常见的。
问题在于,在每个模块中,import discord 都是灰色的(PyCharm IDE),表明从未使用过。尽管如此,我的机器人运行良好。我似乎无法使用wait_for() 命令之类的东西,我想是因为它在discord 模块中?我没有正确设置以使用它吗?
我将发布初始启动模块和另一个模块的小sn-p,而不是列出模块。如果您需要更多信息,请告诉我。
初始启动:
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))
【问题讨论】:
标签: python-3.7 discord.py-rewrite