Input 如何在discord.py的命令提示符上将discord中的消息转换为输入?

Input 如何在discord.py的命令提示符上将discord中的消息转换为输入?,input,bots,discord.py,Input,Bots,Discord.py,我试图让机器人使用命令用户的不一致消息作为输入,但我似乎无法理解。我仍然坚持使用命令提示符版本(请注意,我是这方面的初学者) 好吧,这不是一个永久性的修复,我会编辑它,以便更好的解决方案,当我记得它时,我以前做过类似的事情 但现在,您可以只使用命令 下面是它们的样子: from discord.ext import commands client = commands.Bot(command_prefix="Your chosen command prefix") toke

我试图让机器人使用命令用户的不一致消息作为输入,但我似乎无法理解。我仍然坚持使用命令提示符版本(请注意,我是这方面的初学者)


好吧,这不是一个永久性的修复,我会编辑它,以便更好的解决方案,当我记得它时,我以前做过类似的事情

但现在,您可以只使用命令

下面是它们的样子:

from discord.ext import commands

client = commands.Bot(command_prefix="Your chosen command prefix")
token = 'Your token'


@client.command()
async def Rawdamage(ctx, *, rawdamage=None):
    var1 = rawdamage

@client.command()
async def Defense(ctx, *, defense=None):
    var2 = defense

@client.command()
async def HP(ctx, *, hp=None):
    var3 = hp

@client.command()
async def Pierce(ctx, *, pierce=None):
    var4 = pierce

@client.command()
async def N(ctx, *, n=None):
    var5 = n
    
    
# Your damage system here #



client.run(token)
这样做的目的是,每当发送带有您的命令前缀的消息时,在这些命令的前缀出现之后,它下面的代码就会运行

你看,还有几个参数。(ctx,*,原始损坏=无) ctx是指ctx。*表示后面的任何内容都将存储在rawdamage变量中


因此,如果我在discord中使用/rawdmage 10,您的机器人会将10放入var1中,生成一个包含许多输入的信号命令,并使用以下数据

您可以这样称呼它,
$game 4 8 21 3
,顺序如下:

  • 原始损坏
  • 防卫
  • 惠普
  • 刺穿
导入不一致
从discord.ext导入命令
bot=commands.bot(command_prefix=“$”)
@bot.command()
异步def游戏(ctx,rawdamage:int,defence:int,hp:int,pierce:int):
n=random.randint(1,4)
嵌入=不和谐。嵌入(title='Fight')
如果n==原始损坏:
损坏=未加工损坏*4//3
嵌入.add_字段(name=”造成的伤害“,value=造成的伤害)
嵌入.add_字段(name='HP left',value=HP-damage_done)
其他:
伤害完成=伤害防御+刺穿
嵌入.add_字段(name=”造成的伤害“,value=造成的伤害)
嵌入.add_字段(name='HP left',value=HP-damage_done)
等待ctx.send(嵌入=嵌入)
bot.run('TOKEN HERE')

注意:请确保数学

虽然现在我认为如果你做的游戏对游戏有好处,因为不是所有的东西都会被存储为输入,这会在我的一边造成混乱:我得到了一个错误循环,他们期望在'从迪斯科。ext导入命令'缩进,但当我添加一个时,它告诉我那里有一个意外的缩进…请按原样尝试,只需添加令牌并尝试。等等,别担心,这只是我以前的不幸,谢谢!
from discord.ext import commands

client = commands.Bot(command_prefix="Your chosen command prefix")
token = 'Your token'


@client.command()
async def Rawdamage(ctx, *, rawdamage=None):
    var1 = rawdamage

@client.command()
async def Defense(ctx, *, defense=None):
    var2 = defense

@client.command()
async def HP(ctx, *, hp=None):
    var3 = hp

@client.command()
async def Pierce(ctx, *, pierce=None):
    var4 = pierce

@client.command()
async def N(ctx, *, n=None):
    var5 = n
    
    
# Your damage system here #



client.run(token)