【发布时间】:2022-01-09 18:03:39
【问题描述】:
我是 python 新手,标题中出现错误。我知道问题出在哪里,但我想根据用户在命令中提供的论点创建一个命令来提供不同的结果。
例如,如果它将是“!sens 20 cm 800 dpi”,机器人会回复“{} ingame”,但如果“!sens 10 ingame 800 dpi”,机器人会回复“{} cm”
我不想创建两个不同名称的命令。
import math
import discord
from discord.ext import commands
TOKEN = ''
bot = commands.Bot(command_prefix='!')
d= 166461.6
@bot.command(name="sens")
async def sens_cm(ctx, x: float,cm, y: float,dpi):
await ctx.send('{} ingame'.format(d/(x*y)))
@bot.command(name="sens")
async def sens(ctx, x1: float,ingame, y1: float,dpi):
await ctx.send('{} cm'.format(d/(x1*y1)))
bot.run(TOKEN)
【问题讨论】:
标签: discord discord.py bots