发送消息时前缀是不一致的



我正在制作一个不和谐机器人,它的前缀是"!c",但我希望如果人们发送"!c"出现了嵌入,所以我这样修复了它:

client = commands.Bot(command_prefix='!')
client.remove_command("help")
@client.group()
async def c(ctx):
YourEmbedCodeHere

我想添加一个命令"!c别人;它发送相同的嵌入。我试着这样做:

@c.group(invoke_without_command= True)
async def help(ctx):
embed = discord.Embed(title="ChiBot", description="ChiBot by Chita! A very usefull moderation, level, invite and misc bot!", color=0x62e3f9)
embed.add_field(name="Commands:", value="Do !help (command) to get help on that command!", inline=False)
embed.add_field(name="Misc", value="!c help    !c randomimage    !c invite    !c echo", inline=False)
embed.add_field(name="Moderation", value="!c ban    !c kick    !c warn    !c mute    !c unmute    !c warns      !c warnings", inline=False)
embed.add_field(name="Levels", value="!c rank    !c dashboard   ", inline=False)
embed.add_field(name="Invites", value="!c invites (help with setting it up)", inline=False)
embed.set_footer(text="Created by Chita#8005")
await ctx.send(embed=embed)

但是当我这样做的时候,它会发送double,因为"!仍然是同一个嵌入的命令。如何让它只发送1个嵌入?我想再加一句"!"命令,所以我需要一个解决方案来删除!c嵌入,如果有背后的东西!c

问候,契塔

您可以使用on_message事件侦听器来检查。

@client.listen('on_message')
async def foo(message):
await client.wait_until_ready()
ctx = await client.get_context(message)
if message.content == '!c':
await ctx.send(embed=embed) # send your embed here
return #makes sure that we dont reply twice to `!c`

我们正在使用client.wait_until_ready(),以便客户端在连接之前不响应消息。

可选,您可以添加

if message.author.bot:
return

确保我们不回复机器人。

资源:on_messagewait_until_ready

您可以尝试将前缀保留为"!并且有一个on_message事件来监听一个"!发送嵌入。像这样。

@client.event
async def on_message(message):
if message.content == "!c":
#Your embed code here
await client.process_commands(message)

我希望这可能对你有帮助。

最新更新