首页 > 解决方案 > 无论我尝试多少,bot.command 都不起作用(discord.py)

问题描述

我一直在尝试制作一个不和谐的机器人,我已经能够让它响应消息事件,但我无法让命令工作,我尝试了几乎所有我可以在堆栈上看到的解决方案。我确实收到错误说明

Unused import statement 'import discord':2

这是代码-

from discord.ext import commands
import discord

bot = commands.Bot(command_prefix='.')


@bot.command(pass_context=True)
async def ping(ctx):
    await ctx.send('pong!')


@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    if message.content.startswith('yo'):
        await message.channel.send('yo momma is fat')

bot.run('token')

标签: pythondiscorddiscord.py

解决方案


你不需要pass_context=True,这是很老的,不知道你从哪里得到的,另外,在 discord.ext 之前导入不和谐(仅用于格式化)


推荐阅读