我正在尝试创建一个我的Discord.py机器人的一部分,用人们可以分配的颜色创建一些角色。当我尝试运行时,我得到问题标题中显示的错误。
# 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))
答案 0 :(得分:0)
Bot
是Client
的子类。你不需要创造两者。您还可以在创建角色时为其指定颜色。
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