我可以成为discord.client的子类吗?

时间:2018-11-05 01:53:45

标签: python python-3.x discord.py subclassing

我正在尝试使用discord.py编写一个discord机器人。我想成为discord.client类的子类,以便可以向该类添加一些属性。不幸的是,我一直收到此错误:

  

回溯(最近通话最近):     文件“ C:/Users/laser/PycharmProjects/DiscordNut/main.py”,第5行,在       Bot类(客户端):   TypeError:模块。 init ()最多接受2个参数(给定3个参数)

这是我的代码:

from discord import client
import random as rand


class Bot(client):
    pass


    async def roll(self, *args):
        input = args[0]
        target = input.find('d')
        numDice = int(input[:target])
        diceSize = int(input[target + 1:])
        output = 0
        for i in range(numDice):
            output += rand.randint(1, diceSize)

        await self.send_message(self.get_channel("505154560726269953"), "You rolled a: " + str(output))


def parse(content, delimeter):
    target = content.find(delimeter)
    if content.find("\"") == 0:
        content = content[1:]
        target = content.find("\"")
    if target == 0:
        return parse(content[1:], delimeter)
    elif target < 0:
        return [content]
    else:
        parsed = []
        parsed.append(content[:target])
        return parsed + parse(content[target + 1:], delimeter)


client = Bot()


@client.event
async def on_ready():
    client.users = [i for i in client.get_all_memebers()]
    print(client.users)


@client.event
async def on_message(message):
    parsed = None
    if message.startswith('!'):
        parsed = parse(message.content[1:], " ")
    if parsed[0] in client.commands:
        args = [i for i in parsed if i != parsed[0]]
        client.commands[parsed[0]](args)


client.run("<TOKEN>")

0 个答案:

没有答案