Python 我如何让我的不和机器人回复一个提及?
当有人提到我的不和谐机器人时,我想让它回复。例如,如果@someone键入“Hello@bot”,我希望我的bot回复“Hello@someone!” 我尝试了几种方法: 一, 即使这样,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"
@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) + "!")