提到作者pythonbot

提到作者pythonbot,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我需要让标记作者在这一行这是你的随机{}选择, token = "xxxxxxxxxxxxxxxxxxxxxxxx" prefix = "?" import discord from discord.ext import commands from discord.ext.commands import Bot import random bot = commands.Bot(command_prefix=prefix) bot.remove_command("help") @bot.e

我需要让标记作者在这一行
这是你的随机{}选择,

token = "xxxxxxxxxxxxxxxxxxxxxxxx"
prefix = "?"

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import random 

bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')

answers = ["apple", "ball", "cat", "dog", "elephant", "frog", "gun"]

@bot.command()  
async def choose(k : int):
    """Chooses between multiple choices."""
    if 0 <= k <= 10:
        await bot.say("This is your random {} pick, {}".format(k, ctx.message.author.mention))
        embed = discord.Embed(description='\n'.join(random.choices(answers, k=k)))
        await bot.say(embed=embed)
    else:
        await bot.say("Invalid number")

bot.run(token)
。您可以做的是指定命令的名称,而不是协同程序的名称

@bot.command(pass_context=True)  
async def choose(ctx, k: int):
    """Chooses between multiple choices."""
    if 0 <= k <= 10:
        await bot.say("This is your random {} pick, {}".format(k, ctx.message.author.mention))
        embed = discord.Embed(description='\n'.join(random.choices(answers, k=k)))
        await bot.say(embed=embed)
    else:
        await bot.say("Invalid number")
@bot.command(pass\u context=True)
异步定义选择(ctx,k:int):
“”“在多项选择中进行选择。”“”
如果0那么这很容易

async def (ctx,k : int):
只需添加ctx,您就完成了! 也

将给你错误,而不是使用

ctx.send

因为函数在python语法中不能以数字开头,就这么简单谢谢你兄弟它提供了一些提示如何在这段代码中提到作者
wait bot.say(“这是你的随机{}拾取”。format(k))
你可以使用format在字符串中插入多个值
“这是你的随机{}拾取,{}”。format(k,ctx.message.author.title)
。您也可以使用f-strings
f“这是您的随机{k}选择,{ctx.message.author.title}”
我尝试了此操作,但得到了ctx错误。此问题是您回答的。您能在问题正文中编辑您看到的完整错误吗?您能发布命令和任何错误处理程序的完整代码吗?看起来您在某个地方缺少了一个
pass\u context=True
bot.say
ctx.send