[使用message.content.startswith时如何使Discord机器人对服务器表情符号做出反应

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[使用message.content.startswith时如何使Discord机器人对服务器表情符号做出反应相关的知识,希望对你有一定的参考价值。

那么我如何使我的机器人对cutstom服务器表情符号做出反应?看起来像这样:

if message.content.startswith(":emoji: Hello"): await client.get_channel(123456789).send("Hello to you, too!")

如果我在Discord中发布表情符号和句子,则不会触发该命令。我需要更改什么?

答案

[使用自定义表情符号时,它具有唯一的ID。您可以通过几种不同的方式来访问它,但是最简单的方法可能是\:emoji:,您可以在这里看到它的工作:

enter image description here

enter image description here

enter image description here

最后一部分是消息的内容将包含的内容。因此,在我的情况下,正确的语句应如下所示:

if message.content.lower().startswith("<:statue:709925980029845565> hello"):
    await message.channel.send("Hello to you too!") # sends to the same channel the message came from

您也可以像这样检索ID:

emoji = discord.utils.get(message.guild.emojis, name="statue")
if message.content.lower().startswith(f"emoji hello"):
    await message.channel.send("Hello to you too!")

参考:

以上是关于[使用message.content.startswith时如何使Discord机器人对服务器表情符号做出反应的主要内容,如果未能解决你的问题,请参考以下文章

在使用加载数据流步骤的猪中,使用(使用 PigStorage)和不使用它有啥区别?

今目标使用教程 今目标任务使用篇

Qt静态编译时使用OpenSSL有三种方式(不使用,动态使用,静态使用,默认是动态使用)

MySQL db 在按日期排序时使用“使用位置;使用临时;使用文件排序”

使用“使用严格”作为“使用强”的备份

Kettle java脚本组件的使用说明(简单使用升级使用)