[英]How do I mention a member in a text? Discord bot python
if message.content.startswith('!givecookie @member'):
await message.channel.send('Hello, @member, here is your cookie~ :cookie:')
那么在提及某人时如何向命令添加成员(@member)? 该命令应该做的是 - 将 cookie 提供给成员。
首先,你不应该使用if message.content.startswith(“!givecookie @member")
最好使用client = commands.Bot(command_prefix="!”)
声明客户client = commands.Bot(command_prefix="!”)
。 之后你可以使用
@client.command()
async def givecookie(ctx, member : commands.MemberConverter):
await ctx.send(f"Hello, {member.mention}, here is your cookie~ :cookie:")
这意味着你的机器人现在有前缀“!”,使用@client.command
可以创建更多你可以在不和谐中使用的命令。 此命令中传递的参数 (ctx, member : commands.MemberConverter) 分别表示您要向其提供 cookie 的上下文和特定成员。 ctx.send(f“Hello, {member.mention}, here is your cookie~ :cookie:")
基本上会发送消息,但它也会 ping 成员。告诉机器人发送“@member”将使它的字面意思发送“@member”。 此外,该命令仅在您以“!givecookie @member”开始消息时才有效,但如果您执行“!give cookie {pinging the specific member}”则无效。
总之,您应该使用 client.command() 来使用命令而不是检查消息的内容。
API 参考
https://discordpy.readthedocs.io/en/stable/index.html
前缀: https ://discordpy.readthedocs.io/en/stable/ext/commands/api.html ? highlight = commands#prefix-helpers
命令: https : //discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=commands#commands
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.