【发布时间】:2021-07-24 05:07:05
【问题描述】:
真的不是骗子吗?说明:
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 指出了一个非常严重的复制粘贴错误,我已修复 :)
- 该修复将“成员”设置为命令的参数。我想要的是获取成员显示名称,并在命令输出中使用它(作为@提及)
谷歌答案
@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)
我看过的资源
【问题讨论】:
标签: python discord.py