我试图做到这一点,如果用户使用非整数/浮点对象进行回复,则代码会将机器人收集的消息替换为用户已回复的新消息,并执行此操作,直到用户回复整数或浮点数,我已经尝试这样做了几个小时,但仍然找不到解决方案。
错误告诉我无法将字符串转换为整数,但问题是,代码正在尝试转换用户输入的第一条消息,而不是用户输入的消息如果他们得到了ValueError,则得到了ValueError。
import asyncio
from discord.ext import commands
class HypixelCommands(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print('|----------------------------------------------|')
print('|-----------Hypixel Commands work!-------------|')
print('|----------------------------------------------|')
###########################
#-------Dictionarys-------#
###########################
########################
#-------COMMANDS-------#
########################
@commands.command(name='minionprofit', aliases=['minion', 'mp', 'minioncalculator'])
async def minionprofit(self, ctx, *, arg:str=None):
# checks if the input is integer or not, if not acts like a errorr
async def user_input_function(input):
boolean = False
while boolean == False:
try:
int(float(input.content))
if type(input.content) == int or float:
input.content = input.content
break
except ValueError:
await ctx.send('**Please type in a number!**')
input = await self.client.wait_for("message", check=lambda message: message.author == ctx.message.author, timeout=10)
# what is the sell price per item?
embed = discord.Embed(color=discord.Color.gold())
embed.set_author(name='Minion Calculator', icon_url='https://hywikis.com/skyblock/images/thumb/c/cf/Cobblestone_Minion.png/282px-Cobblestone_Minion.png')
embed.add_field(
name="*This minion calculator is in it's Alpha state, so if you find any bugs please report it to* **MythCraftMC#0963**",
value='Please answer the following questions!',
inline=False)
embed.add_field(name='**What is the sell price per item?**', value=None)
embedMSG = await ctx.send(embed=embed)
try:
sell_msg = await self.client.wait_for("message", check=lambda message: message.author == ctx.message.author, timeout=10)
await user_input_function(sell_msg)
except TimeoutError:
timeouterror = await ctx.send('**You ran out of time!**')
await asyncio.sleep(3)
await timeouterror.delete()
else:
await embedMSG.delete()
# What is the minion's speed?
embed = discord.Embed(color=discord.Color.gold())
embed.set_author(name='Minion Calculator', icon_url='https://hywikis.com/skyblock/images/thumb/c/cf/Cobblestone_Minion.png/282px-Cobblestone_Minion.png')
embed.add_field(
name="*This minion calculator is in it's Alpha state, so if you find any bugs please report it to* **MythCraftMC#0963**",
value='Please answer the following questions!',
inline=False)
embed.add_field(name="**What is the minion's speed?**", value=None)
embedMSG = await ctx.send(embed=embed)
try:
speed_msg = await self.client.wait_for("message", check=lambda message: message.author == ctx.message.author, timeout=10)
await user_input_function(speed_msg)
except TimeoutError:
timeouterror = await ctx.send('**You ran out of time!**')
await asyncio.sleep(3)
await timeouterror.delete()
else:
await embedMSG.delete()
# Items per action?
embed = discord.Embed(color=discord.Color.gold())
embed.set_author(name='Minion Calculator', icon_url='https://hywikis.com/skyblock/images/thumb/c/cf/Cobblestone_Minion.png/282px-Cobblestone_Minion.png')
embed.add_field(
name="*This minion calculator is in it's Alpha state, so if you find any bugs please report it to* **MythCraftMC#0963**",
value='Please answer the following questions!',
inline=False)
embed.add_field(name="**What is the minion's item per action?**", value='Means how many items does the minion get when they break a block or kill something?')
embedMSG = await ctx.send(embed=embed)
try:
print('Inside the try function') # DELTE THIS
items_msg = await self.client.wait_for("message", check=lambda message: message.author == ctx.message.author, timeout=10)
print('After await function') ## DELTE THIS
await user_input_function(items_msg)
print('DONE WITH TRY FUNCTION')
except TimeoutError:
timeouterror = await ctx.send('**You ran out of time!**')
await asyncio.sleep(3)
await timeouterror.delete()
else:
try:
# Final Message
await embedMSG.delete()
# calculation/conclusion
profit = (86400/int(float(speed_msg.content))*(int(float(items_msg.content))/2)*int(float(sell_msg.content)))
embed = discord.Embed(color=discord.Color.gold())
embed.set_author(name='Minion Calculator', icon_url='https://hywikis.com/skyblock/images/thumb/c/cf/Cobblestone_Minion.png/282px-Cobblestone_Minion.png')
embed.add_field(
name="*This minion calculator is in it's Alpha state, so if you find any bugs please report it to* **MythCraftMC#0963**",
value='This is the profit from the NPC without any upgrades of fuels!',
inline=False)
embed.add_field(name=f"*Your minion will make about,* **{round(profit)}** in 24 hours! :smile:", value='Please know that the profit could be a bit more or less than this! No minion calculator is perfect.')
embedMSG = await ctx.send(embed=embed)
except Exception as error:
print(f'GOT A ERROR : {error}')
await ctx.send('There was a error while running this command! please contact MythCraftMC#0963 for support!')
def setup(client):
client.add_cog(HypixelCommands(client))```