Discord Bot Python-通过未知数的参数



当前与discord.py bot混乱,我正在努力将多个未知值传递到此函数中。在此示例中,我允许用户添加多个数字,但我不知道它是否为200个数字。

使用下面的代码我获得了一个类对象,我似乎无法通过0x032aab10的discord.ext.commands.context.context.context对象进行迭代。

我的类从以下代码中继承从音乐类继承,https://github.com/rapptz/discord.py/blob/ashync/examples/playlist.py.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))

如何从此对象中获取变量?我很可能做了一些愚蠢或不完全理解我在做什么的事情,所以请提前道歉:D

谢谢约翰

您要求上下文传递给您的函数,这已成为*nums中的第一个参数。只需将pass_context设置为False,或将功能签名更改为async def add(self, ctxt, *nums)

最新更新