Discord.py-如何从Bot命令[重复]中提及不和谐的用户

问题描述 投票:2回答:1

真的不是骗子吗?说明:This question is not looking to (at)mention a userThis question lists member.mention but does not provide a complete example

我的问题使用Discord.py(如果标题不清楚),我试图弄清楚如何在他们运行命令时向Discord用户添加@ mention属性。

示例:用户输入:$ 99Bot输出:@ User您的报价是:Bingpot!

更新:10/24/2019-@ epic-programmer指出了一个非常严重的复制粘贴错误,我已修复它:)-该修补程序将“成员”设置为命令的参数。我想要得到的是成员的显示名称,并在命令输出中使用它(作为@mention)

Google回答

@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
1个回答
1
投票

member参数在错误的位置。尝试将其移至def语句。

@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)
© www.soinside.com 2019 - 2024. All rights reserved.