<分区>
真的不是骗子吗?解释:
This question is not looking to (at)mention a user
This question lists member.mention but does not provide a complete example
我的问题
使用 Discord.py(如果标题不够清楚)我试图弄清楚如何在运行命令时向 Discord 用户添加 @mention 属性。
示例:
用户输入:$99
机器人输出:@User 你的报价是:Bingpot!
更新:2019 年 10 月 24 日
- @epic-programmer 指出了一个非常严重的复制粘贴错误,我已经修复了 :)
- 该修复程序将“member”设置为命令的参数。我想要的是获取成员显示名称,并在命令输出中使用它(作为 @mention)
谷歌答案
@commands.command()
async def mention_ping(self, ctx, member : discord.Member):
await ctx.send(f"PONG {member}")
我的代码(更新:使用@epic-programmers 部分修复)
import random
import discord
from discord.ext import commands
#----
tokenfile = 'token.txt'
with open(tokenfile) as tf:
line = tf.readline()
TOKEN = line.rstrip()
#----
bot = commands.Bot(command_prefix='$')
@bot.command(name='99', help='Responds with a random quote from Brooklyn 99')
async def nine_nine(ctx, member : discord.Member):
brooklyn_99_quotes = [
'I\'m the human form of the 💯 emoji.',
'Bingpot!',
(
'Cool. Cool cool cool cool cool cool cool, '
'no doubt no doubt no doubt no doubt.'
),
]
response = random.choice(brooklyn_99_quotes)
await ctx.send("{} your quote is: {}".format(member, response))
bot.run( TOKEN)