python - 无论我尝试多少,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')
解决方案
你不需要pass_context=True
,这是很老的,不知道你从哪里得到的,另外,在 discord.ext 之前导入不和谐(仅用于格式化)
推荐阅读
- python-3.x - 在列表对象列表中,如何将每个列表对象与所有其他列表对象进行比较?
- angular - 我可以创建多个 MsalService 实例吗
- r - 从 R 中的 for 循环创建数据框,其中包含 if-else 语句
- scala - 是否有理由使用 s String 插值而不是 f String 插值?
- c# - C# SelectCommand 属性在调用“填充”之前尚未初始化。在 WinForm 中
- jquery - 如何为要在表格中显示的数据动态分配行跨度?
- reactjs - 使用reach-router在同一路由器中拆分路由
- entity-framework - .AsNoTracking() 对于某些实体框架始终开启 DbSets
- regex - 如何从 Google 表格中的过滤器中选择多个值?
- python - 如何在两个熊猫数据框中多处理查找最近的地理点?