discord - 发送前缀时发送消息 discord.py
问题描述
我正在制作一个前缀为“!c”的不和谐机器人,但我希望如果人们发送“!c”会显示嵌入,所以我通过这样做来修复它:
client = commands.Bot(command_prefix='!')
client.remove_command("help")
@client.group()
async def c(ctx):
YourEmbedCodeHere
我想添加一个命令“!c help”,它发送相同的嵌入。我尝试这样做:
@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)
但是当我尝试这样做时,它会发送双倍,因为“!c”仍然是同一嵌入的命令。我怎样才能使它只发送1个嵌入?而且我还想添加其他“!c”命令,所以如果 !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
确保我们不会回复机器人。
推荐阅读
- javascript - 通过 JavaScript 在 ins 标记内多次添加值
- c# - 使用多个排序条件对 System.Data.DataTable 进行排序
- c - 调用 libusb_bulk_transfer 或 libusb_interrupt_transfer 时出现“LIBUSB_ERROR_NOT_FOUND”错误
- go - “Go 并发模式:超时,继续”博客中的非阻塞通道
- asp.net - 当 user2 在数据库中更新/添加记录时自动刷新 user1 的页面
- python - 如何正确处理单个元素的迭代导致抛出错误的情况?
- delphi - 如何以短数据格式在参数中传递值
- ros - 用于雷达实施的 UKF
- javascript - 如何在 TypeScript 中默认导出文件夹?
- sql-server - 通过链接服务器识别 SQL Server 数据库和 Oracle 之间的对象依赖关系?