Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我如何让我的不和机器人回复一个提及?_Python_Discord.py - Fatal编程技术网

Python 我如何让我的不和机器人回复一个提及?

Python 我如何让我的不和机器人回复一个提及?,python,discord.py,Python,Discord.py,当有人提到我的不和谐机器人时,我想让它回复。例如,如果@someone键入“Hello@bot”,我希望我的bot回复“Hello@someone!” 我尝试了几种方法: 一, 即使这样, @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith("@bot"

当有人提到我的不和谐机器人时,我想让它回复。例如,如果@someone键入“Hello@bot”,我希望我的bot回复“Hello@someone!”

我尝试了几种方法: 一,

即使这样,

@client.event
    async def on_message(message):
      if message.author == client.user:
        return
      if message.content.startswith("@bot"):
        await message.channel.send("Hello {}".format(message.author.mention) + "!")
但这些都不起作用


那么,如何让我的discord机器人回复提及?

discord提及不是这样处理的,它们的内部格式如下所示:

-正常提及
-尼克提到
-角色提及
-频道提及
您可以创建一个简单的正则表达式:

重新导入
@客户端事件
异步def on_消息(消息):
如果message.author==client.user:
返回
pattern=re.compile(f“hello”)#感叹号是可选的
如果pattern.match(message.content.lower())不是None:#检查消息是否与我们的模式匹配
wait message.channel.send(f“Hello{message.author.ention}!”)

不和谐的提及不是这样处理的,它们的内部格式如下所示:

-正常提及
-尼克提到
-角色提及
-频道提及
您可以创建一个简单的正则表达式:

重新导入
@客户端事件
异步def on_消息(消息):
如果message.author==client.user:
返回
pattern=re.compile(f“hello”)#感叹号是可选的
如果pattern.match(message.content.lower())不是None:#检查消息是否与我们的模式匹配
wait message.channel.send(f“Hello{message.author.ention}!”)
@client.event
    async def on_message(message):
      if message.author == client.user:
        return
      if message.content.startswith("@bot"):
        await message.channel.send("Hello {}".format(message.author.mention) + "!")