【发布时间】:2021-05-21 12:50:54
【问题描述】:
我想从 on_message() 运行命令,但 bot.get_context() 返回协程对象,而不是上下文。 代码给出的错误:await bot.get_context(message).invoke(bot.get_command("do_something")) AttributeError: 'coroutine' 对象没有属性 'invoke'
import discord, asyncio
from discord.ext import commands, tasks
bot_token = ""
bot = commands.Bot(command_prefix=("!"))
@bot.event
async def on_message(message):
#print(type(bot.get_context(message)))
if message.content == "do something":
await bot.get_context(message).invoke(bot.get_command("do_something"))
await bot.process_commands(message)
@bot.command()
async def do_something(ctx):
#print(type(ctx))
await ctx.send("Working")
bot.run(bot_token)
【问题讨论】:
标签: python-3.x discord.py