本文整理汇总了Python中discord.Color方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Color方法的具体用法?Python discord.Color怎么用?Python discord.Color使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Color方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def __init__(self, cog, data):
self.cog = cog
self.data = data
self.name = data["name"]
self.race = data["race"]
self.gender = data["gender"].lower()
self.profession = data["profession"].lower()
self.level = data["level"]
self.specializations = data.get("specializations")
self.color = discord.Color(
int(self.cog.gamedata["professions"][self.profession]["color"],
16))
self.created = datetime.datetime.strptime(data["created"],
"%Y-%m-%dT%H:%M:%Sz")
self.age = data["age"]
self.spec_cache = {}
示例2: sendembed
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def sendembed(self, ctx, color:Optional[discord.Color]=None, *, text):
"""
Send an embed.
Use the optional parameter `color` to change the color of the embed.
The embed will contain the text `text`.
All normal discord formatting will work inside the embed.
"""
if color is None:
color = await ctx.embed_color()
embed = discord.Embed(
description=text,
color=color
)
await ctx.send(embed=embed)
try:
await ctx.message.delete()
except discord.Forbidden:
pass
示例3: modlogs
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def modlogs(self, ctx, user: UserWithFallback = None):
if not user:
user = ctx.author
mlogs = await self.bot.db.fetch(
'SELECT * FROM modlogs WHERE uid=$1 AND gid=$2',
user.id,
ctx.guild.id
)
if not mlogs:
return await ctx.error('No modlogs found')
paginator = WrappedPaginator(prefix='', suffix='')
for log in mlogs:
paginator.add_line(f'**Case ID**: {log["caseid"]}\n'
f'**Type**: {log["type"].capitalize()}\n'
f'**User**: {user}\n'
f'**Reason**: {log["reason"]}\n'
f'**Date**: {log["date"]}\n'
f'**-----------------**')
embed = discord.Embed(color=discord.Color(15105570), timestamp=datetime.datetime.now(datetime.timezone.utc))
interface = PaginatorEmbedInterface(ctx.bot, paginator, owner=ctx.author, _embed=embed)
await interface.send_to(ctx)
示例4: userdata_info
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def userdata_info(self, ctx, member: discord.Member=None):
"""Display user data."""
self.init_server(ctx)
self.init_user(ctx)
server = ctx.message.server
if member is None:
member = ctx.message.author
if member.id not in self.settings[server.id]["users"]:
await self.bot.say("User does not have any user data set.")
return
color = ''.join([choice('0123456789ABCDEF') for x in range(6)])
color = int(color, 16)
em = discord.Embed(
color=discord.Color(value=color))
em.set_author(name=member.display_name)
for k, v in self.settings[server.id]["users"][member.id].items():
em.add_field(name=k, value=v)
await self.bot.say(embed=em)
示例5: get_profession
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def get_profession(self, profession, specializations):
async def get_elite_spec():
try:
spec = specializations[-1]
except IndexError:
return None
if spec:
if not spec["elite"]:
return None
return spec["name"]
return None
def get_icon_url(prof_name):
base_url = ("https://api.gw2bot.info/"
"resources/professions/{}_icon.png")
return base_url.format(prof_name.replace(" ", "_").lower())
Profession = collections.namedtuple("Profession",
["name", "icon", "color"])
color = discord.Color(
int(self.gamedata["professions"][profession.lower()]["color"], 0))
name = await get_elite_spec() or profession
icon = get_icon_url(name)
return Profession(name.title(), icon, color)
示例6: _load_roles
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def _load_roles(self):
log.debug(f"Loading roles on {self.guild.id}")
existing_roles = list(reversed(list(filter(
lambda r: not r.managed and not r.is_default()
and self.guild.me.top_role.position > r.position,
self.guild.roles
))))
for role in reversed(self.data["roles"]):
try:
if role["default"]:
await self.guild.default_role.edit(
permissions=discord.Permissions(role["permissions"])
)
new_role = self.guild.default_role
else:
kwargs = {
"name": role["name"],
"hoist": role["hoist"],
"mentionable": role["mentionable"],
"color": discord.Color(role["color"]),
"permissions": discord.Permissions.none(),
"reason": self.reason
}
if len(existing_roles) == 0:
try:
new_role = await asyncio.wait_for(self.guild.create_role(**kwargs), 10)
except asyncio.TimeoutError:
# Probably hit the 24h rate limit. Just skip roles
break
else:
new_role = existing_roles.pop(0)
await new_role.edit(**kwargs)
self.id_translator[role["id"]] = new_role.id
except Exception:
pass
示例7: embed_message
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def embed_message(content=None, title=None, type=None):
emb_title, content_format, icon, color = message_types.get(type) or message_types.get(None)
title = title or emb_title
embed = discord.Embed(color=discord.Color(color), description=content_format.format(c=content))
embed.set_author(name=title, icon_url=icon)
return {"embed": embed}
示例8: changelog
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def changelog(self, ctx):
"""Gets a rough changelog for mangobyte
Note that this is a very rough changelog built from git commit messages and so will sometimes not relate directly to your perspective.
For more commit versions or better detailed information, check out the source on [GitHub](https://github.com/mdiller/MangoByte/commits/master)
"""
commit_url = "https://github.com/mdiller/MangoByte"
description = f"For more information check out the [commit history]({commit_url}/commits/master) on GitHub\n"
lines = get_changelog().split("\n")
recent_date = 0
for line in lines:
if line == "":
continue
commit = line.split(",")
full_sha = commit[0]
timestamp = int(commit[1])
small_sha = commit[2]
message = ",".join(commit[3:])
if timestamp > recent_date:
recent_date = timestamp
description += f"\n[`{small_sha}`]({commit_url}/commit/{full_sha}) {message}"
if recent_date != 0:
embed = discord.Embed(description=description, color=discord.Color.green(), timestamp=datetime.datetime.utcfromtimestamp(recent_date))
embed.set_footer(text="Most recent change at")
else:
embed = discord.Embed(description=description, color=discord.Color.green())
embed.set_author(name="Changelog", url=f"{commit_url}/commits/master")
await ctx.send(embed=embed)
示例9: info
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def info(self, ctx):
"""Prints info about mangobyte"""
github = "https://github.com/mdiller/MangoByte"
python_version = "[Python {}.{}.{}]({})".format(*os.sys.version_info[:3], "https://www.python.org/")
discordpy = "https://github.com/Rapptz/discord.py"
embed = discord.Embed(description="The juiciest unsigned 8 bit integer you eva gonna see", color=discord.Color.green())
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url, url=github)
embed.add_field(name="Development Info", value=(
"Developed as an open source project, hosted on [GitHub]({}). "
"Implemented using {} and a python discord api wrapper [discord.py]({})".format(github, python_version, discordpy)))
help_guild_link = "https://discord.gg/d6WWHxx"
embed.add_field(name="Help", value=(
f"If you want to invite mangobyte to your server/guild, click this [invite link]({invite_link}). "
f"If you have a question, suggestion, or just want to try out mah features, check out the [Help Server/Guild]({help_guild_link})."))
cmdpfx = self.cmdpfx(ctx)
embed.add_field(name="Features", value=(
f"• Answers questions (`{cmdpfx}ask`)\n"
f"• Plays audio clips (`{cmdpfx}play`, `{cmdpfx}dota`)\n"
f"• Greets users joining a voice channel\n"
f"• For a list of command categories, try `{cmdpfx}help`"), inline=False)
embed.add_field(name="Donate", value=(
f"If you want to donate money to support MangoByte's server costs, click [here]({self.donation_link})"))
owner = (await self.bot.application_info()).owner
embed.set_footer(text="MangoByte developed by {}".format(owner.name), icon_url=owner.avatar_url)
await ctx.send(embed=embed)
示例10: botstats
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def botstats(self, ctx):
"""Displays some bot statistics"""
await ctx.channel.trigger_typing()
embed = discord.Embed(color=discord.Color.green())
embed.set_author(name=self.bot.user.name, icon_url=self.bot.user.avatar_url)
embed.add_field(name="Servers/Guilds", value="{:,}".format(len(self.bot.guilds)))
embed.add_field(name="Registered Users", value="{:,}".format(botdata.count_users_with_key("steam")))
thisweek = "timestamp between datetime('now', '-7 days') AND datetime('now', 'localtime')"
query_results = await loggingdb.query_multiple([
f"select count(*) from messages where command is not null",
f"select count(*) from messages where command is not null and {thisweek}",
f"select command from messages where command is not null group by command order by count(command) desc limit 3",
f"select command from messages where command is not null and {thisweek} group by command order by count(command) desc limit 3"
])
# embed.add_field(name="Commands", value=f"{query_results[0][0][0]:,}")
embed.add_field(name="Commands (This Week)", value=f"{query_results[1][0][0]:,}")
cmdpfx = self.cmdpfx(ctx)
top_commands = query_results[2]
# if len(top_commands) >= 3:
# embed.add_field(name="Top Commands", value=(
# f"`{cmdpfx}{top_commands[0][0]}`\n"
# f"`{cmdpfx}{top_commands[1][0]}`\n"
# f"`{cmdpfx}{top_commands[2][0]}`\n"))
top_commands_weekly = query_results[3]
if len(top_commands_weekly) >= 3:
embed.add_field(name="Top Commands (This Week)", value=(
f"`{cmdpfx}{top_commands_weekly[0][0]}`\n"
f"`{cmdpfx}{top_commands_weekly[1][0]}`\n"
f"`{cmdpfx}{top_commands_weekly[2][0]}`\n"))
await ctx.send(embed=embed)
示例11: poke_color
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def poke_color(color):
return {
"black": discord.Color(0x000000),
"blue": discord.Color.blue(),
"brown": discord.Color(0xD2691E),
"gray": discord.Color(0xA9A9A9),
"green": discord.Color.green(),
"pink": discord.Color(0xFF69B4),
"purple": discord.Color.purple(),
"red": discord.Color.red(),
"white": discord.Color(0xFFFFFF),
"yellow": discord.Color(0xFFFF00)
}[color]
示例12: neutralitems
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def neutralitems(self, ctx, *, tier = None):
"""Displays all of the neutral items
If a tier is specified, display the items in that tier, along with their names
`{cmdpfx}neutralitems`
`{cmdpfx}neutralitems tier 5`
`{cmdpfx}neutralitems 3`"""
if tier is not None:
tier = tier.lower().replace("tier", "").replace("t", "").strip()
if not tier.isdigit():
raise UserError("Please specify a tier like 'tier 5'")
tier = int(tier)
if tier < 1 or tier > 5:
raise UserError("Please specify a tier between 1 and 5")
embed = discord.Embed()
title = "Neutral Items"
if tier is not None:
title = f"Tier {tier} Neutral Items"
embed.title = title
embed.url = "https://dota2.gamepedia.com/Neutral_Items"
all_neutral_items = session.query(Item).filter(Item.neutral_tier != None).order_by(Item.localized_name).all()
image = discord.File(await drawdota.draw_neutralitems(tier, all_neutral_items), "neutralitems.png")
embed.set_image(url=f"attachment://{image.filename}")
if tier is not None:
tier_color = drawdota.neutral_tier_colors[str(tier)]
embed.color = discord.Color(int(tier_color[1:], 16))
if tier is None:
embed.set_footer(text="Also try: ?neutralitems tier 4")
await ctx.send(embed=embed, file=image)
示例13: card
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def card(self, ctx, *, card_name : str=None):
"""Displays info about the artifact card
Example:
`{cmdpfx}artifact Healing Salve`
`{cmdpfx}artifact Prowler Vanguard`
`{cmdpfx}artifact keefe`"""
card = self.find_card(card_name)
if card is None:
raise UserError(f"Couldn't find any card with the name '{card_name}'")
embed = discord.Embed(color=discord.Color(card.color.integer))
if card.mini_image:
embed.set_author(name=card.name, icon_url=card.mini_image)
else:
embed.set_author(name=card.name)
if card.large_image:
embed.set_image(url=card.large_image)
elif card.text:
embed.description = card.text
if card.references:
descriptions = []
for ref in card.references:
ref_type = format_pascal_case(ref.ref_type.replace("_", " "))
if ref.count:
ref_type += f" (x{ref.count})"
if ref.card.name == card.name:
continue
descriptions.append(f"{ref_type}: **{ref.card.name}**")
if descriptions:
embed.description = "\n".join(descriptions)
embed.set_footer(text=f"Set: {card.set.name}")
await ctx.send(embed=embed)
示例14: _embed
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def _embed(
color: Union[int, discord.Color] = None,
title: str = None,
description: str = None,
image: str = None,
footer: Optional[str] = None,
):
em = discord.Embed(color=color, title=title, description=description)
em.set_image(url=image)
if footer:
em.set_footer(text=footer)
return em
示例15: color_converter
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Color [as 别名]
def color_converter(color):
if type(color) is int:
if color < 0 or color > 0xffffff:
raise ValueError('Color value is outside of valid range')
return '%06x' % color
color = color.strip('#')
if color.startswith('0x'):
color = color[2:]
if len(color) != 6 or set(color) - set(string.hexdigits):
raise ValueError('Invalid color hex value')
return color