这是我的main.py代码的一部分
import discord
from discord.ext import commands
from os import listdir
for filename in listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f'cogs.{filename[:-3]}')
此代码是一个齿轮,已添加到main.py
import discord
from discord.ext import commands
import json
class GameCommands(commands.Cog):
def __init__(self, bot):
self.bot = bot
def leerjson(self):
jugador = None
with open("cogs/personajes.json", 'r') as contenido:
jugador = json.load(contenido)
return jugador
def inventario(self, jugador, idmem):
casillas = ":x::one: :two: :three: :four: :five: :six: :seven: :eight: :nine:\n:one:"
for i in range(27):
if "name" in jugador[idmem]["slot"][i]:
casillas = casillas + jugador["objetos"][jugador[idmem]["slot"][i]["name"]]
else:
casillas = casillas + ":blue_square:"
if i == 8:
casillas = casillas + "\n\n:two:"
if i == 17:
casillas = casillas + "\n\n:three:"
return casillas
@commands.command(aliases=['inv', 'objetos', 'obj'])
async def inventario(self, ctx):
p = self.leerjson()
if str(ctx.message.author.id) in p:
inv = self.inventario(p, ctx.message.author.id)
inventario = discord.Embed(
title="Inventario",
color = discord.Colour.blue()
)
inventario.add_field(name=ctx.message.author, value=inv)
await ctx.send("hola",embed=inventario)
else:
await ctx.send(f'{ctx.message.author.mention} Aún no has creado un personaje, usa `prb>empezar` para hacerlo.')
def setup(bot):
bot.add_cog(GameCommands(bot))
当我尝试调用命令“ inventario”时,会发送嵌入变量(inventario),但同时出现此错误。
C:\Users\Admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py:83: RuntimeWarning: coroutine 'Command.__call__' was never awaited
ret = await coro(*args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
有人知道为什么吗?