Reputation: 62
Currently messing about with the Discord.py Bot and I am struggling to pass multiple unknown values into this function. In this example I'm allowing the user to add multiple numbers but I don't know whether it will be 2 numbers of 200 numbers.
Using the code below I get an class object which I cannot seem to iterate through (discord.ext.commands.context.Context object at 0x032AAB10).
My class inherits from the Music class from the following code, https://github.com/Rapptz/discord.py/blob/async/examples/playlist.py
class John_Bot(Music):
@commands.command(pass_context=True, no_pm=True)
async def add(self, *nums):
result = 0
for num in nums:
try:
result += num
except:
await self.bot.say("Numbers only please")
break
await self.bot.say("{} = {}".format((' + '.join(map(str, list(nums)))), result))
How do I get the variables out of this object? Most likely I've done something stupid or not fully understood what I am doing, so apologise in advance :D
Thanks, John
Upvotes: 0
Views: 2032
Reputation: 6103
You're requesting that the context get passed to your function, which is becoming the first argument in *nums
. Simply set pass_context
to False
, or change the function signature to async def add(self, ctxt, *nums)
.
Upvotes: 1