我的机器人总是在有人提到他时发送消息,但我只想在他们的消息内容只有一个提及时才响应机器人。 例如,当我发送 @bot a 时,他向我发送了等待消息,我想删除它并使机器人仅在有人发送 @bot 时才发送等待消息
if message.content.startswith('<@868346872438345738>') or message.content.startswith('<@!868346872438345738>'):
await message.reply(f'Olá {message.author.name}, o meu prefixo é {bot.user.mention} ou {altprefix}! para mais ajuda use {altprefix}help', mention_author=False)
答案 0 :(得分:1)
问题是您使用了startswith(),它忽略了指定序列之后的所有字符。
您可以将 message.content 转换为字符串并执行您需要的所有检查。
像这样:
if message.content.startswith('<@868346872438345738>') or message.content.startswith('<@!868346872438345738>'):
if str(message.content) == "@bot":
await message.reply(f'Olá {message.author.name}, o meu prefixo é {bot.user.mention} ou {altprefix}! para mais ajuda use {altprefix}help', mention_author=False)
答案 1 :(得分:0)
这段代码对我有用
if str(ctx.content) == f"<@{self.bot.user.id}>" or str(ctx.content) == f"<@!{self.bot.user.id}>":