繁体   English   中英

如何让我的 discord.py 机器人向我重复触发词?

[英]How do I make my discord.py bot repeat the trigger word back to me?

所以我希望我的discord.py机器人在它发送的消息中使用触发侦听器响应的词。

例如:

@commands.Cog.listener()
async def on_message(self, message):
    if message.author == self.bot.user:
        return
    msg = message.content
    
    trigger = ["cat", "dog", "Snake", "Rabbit"]
    
    embed = discord.Embed(description=f"{animal} is the best animal!")

    if any(word in msg for word in trigger):
        await message.channel.send(embed=embed)

在这一点上,我需要做的就是定义什么是animal 我知道我可以为每个单词写一个自定义答案,但我必须为我添加到列表中的每一个动物写一个答案,这需要很长时间。 所以我想让代码首先选择触发响应的单词。

所以当我输入“我爱我的猫”时,机器人会回复“猫是最好的动物!”

它可能非常简单,我只是看不到它,但提前感谢您的帮助!

看来您的思路是正确的。 您所要做的就是遍历动物列表; 如果其中一只动物包含在message.content中,则将动物格式化为嵌入并发送嵌入。

@commands.Cog.listener()
async def on_message(self, message):
    if message.author == self.bot.user:
        return
    
    trigger = ["cat", "dog", "Snake", "Rabbit"]
    
    for animal in trigger:
        if animal in message.content:
            embed = discord.Embed(description=f"{animal} is the best animal!")
            await message.channel.send(embed=embed)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM