【发布时间】:2020-12-31 23:07:24
【问题描述】:
我正在尝试制作一些机器人调用它们的“有趣”命令,并且我想嵌入它们。但是它没有吐出任何东西,甚至没有出现不和谐的错误,也没有出现在命令提示符上,这让我不知道如何改进代码。我还想实现一种使用成员的方法:commands.Greedy[discord.Members] 代码,这样我就可以找到该命令的目标,但我认为我需要先解决这个问题。关于如何做到这一点的任何建议?
我也很困惑,因为我使用.format 和f 字符串来尝试使用参数,我也尝试使用message,但这给了我一个语法错误'错误'列表'对象没有属性'提到''。我真的无法理解命令上的文档,因为它们并没有真正给出任何实际代码的示例,而且我不擅长理解新东西。有人能解决这个问题吗?
from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='0!')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('Sample Text'):
await message.channel.send('Sample Text')
@bot.command()
async def slap(ctx):
embed = discord.Embed(color=0x00ff00, title='OH! Z E S L A P !', description="ooh, that hurt.")
embed.add_field(name="Man behind the slaughter:", value="test")
await ctx.send(embed=embed)
bot.run('token here')```
-During this edit, when I just had the 'bot command' area, It seemed to have functioned still. This makes it even more confusing...
【问题讨论】:
-
您能否更新您的问题,使您的代码为minimal, reproducible example?这可能是一个
on_message事件停止你的命令,但不能说没有完整的例子。 -
完成!我这样做了,我认为这是您所说的
on_message,但我需要更多帮助和这部分的详细信息;~; -
您需要将
await bot.process_commands(message)添加到您的on_message事件中。见here。 -
是的!非常感谢。
标签: python bots embed discord.py