首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Discord.py机器人TypeError:__init__()接受1个位置参数,但给出了2个

Discord.py机器人TypeError:__init__()接受1个位置参数,但给出了2个
EN

Stack Overflow用户
提问于 2018-06-07 06:14:29
回答 1查看 1.1K关注 0票数 -2

我正在尝试创建我的Discord.py机器人的一部分,它创建一些带有颜色的角色,人们可以分配。当我尝试运行它时,我得到了问题标题中显示的错误。

代码语言:javascript
复制
# Imports

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio


# Variables

Client = discord.Client()
client = commands.Bot(command_prefix = ">")
colours = ["Mint","Green","Blue","Pink","Purple","Yellow","Red","Black","White","Gold","Aqua"]
colourshex = ["1abc9c","2ecc71","3498db","e91e63","9b59b6","f1c40f","e74c3c","080808","ffffff","ffa800","00e5ff"]

# Enable


@client.event
async def on_ready():
print("Welcome to my bot")


# Module commands
@client.event
async def on_message(message):
    if message.content.lower().startswith(">module"):
        split = message.content.split(" ")
        if split[1].lower() == "colour":
            if split[2].lower() == "on":
                for x in range(0, len(colours)-1):
                    colourx = "Colour-%s" % colours[x]
                    colourxh = colourshex[x]
                    colourful = colourx + " " + colourxh
                    await client.send_message(message.channel, colourful)
                    await client.create_role(message.server, name=colourx)
                    await client.edit_role(server=message.server, role=discord.Role(colourx), colour=discord.Colour(colourxh))
EN

回答 1

Stack Overflow用户

发布于 2018-06-07 06:32:18

BotClient的一个子类。您不需要同时创建这两个文件。您还可以在创建角色时为其分配颜色。

代码语言:javascript
复制
bot = commands.Bot(command_prefix = ">")

colours = ["Mint","Green","Blue","Pink","Purple","Yellow","Red","Black","White","Gold","Aqua"]
colourshex = ["1abc9c","2ecc71","3498db","e91e63","9b59b6","f1c40f","e74c3c","080808","ffffff","ffa800","00e5ff"]

colourdict = dict(zip(colours, colourshex))

@bot.command(pass_context=True)
async def colours(ctx):
    for name, hex in colourdict.items():
        await bot.say("Colour-{} {}".format(name, hex))
        await bot.create_role(ctx.message.server, name=name, colour=discord.Colour(hex))

bot.run("TOKEN")

您可以使用>colours调用上面的代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50730397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档