本文整理汇总了Python中discord.Embed方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Embed方法的具体用法?Python discord.Embed怎么用?Python discord.Embed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Embed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: challenge
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def challenge(self, ctx: Context, number: int = 1):
"""Show the provided challenge number."""
challenge = await get_challenge(number)
description = challenge["challenge"]
if len(description) > 2048:
description = description[:2045] + "..."
embed = Embed(
title=challenge["title"],
colour=Colour(0xE5E242),
url=f"https://www.kingsmathsschool.com/weekly-maths-challenge/{challenge['slug']}",
description=description,
)
embed.set_image(url=challenge["image"])
embed.set_thumbnail(
url="https://pbs.twimg.com/profile_images/502115424121528320/hTQzj_-R.png"
)
embed.set_author(name="King's Maths School")
embed.set_footer(
text=f"Challenge Released: {challenge['published']} | Category: {challenge['category']}"
)
return await ctx.send(embed=embed)
示例2: roles_info
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def roles_info(self, ctx: Context) -> None:
"""Returns a list of all roles and their corresponding IDs."""
# Sort the roles alphabetically and remove the @everyone role
roles = sorted(ctx.guild.roles[1:], key=lambda role: role.name)
# Build a list
role_list = []
for role in roles:
role_list.append(f"`{role.id}` - {role.mention}")
# Build an embed
embed = Embed(
title=f"Role information (Total {len(roles)} role{'s' * (len(role_list) > 1)})",
colour=Colour.blurple()
)
await LinePaginator.paginate(role_list, ctx, embed, empty=False)
示例3: assess
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def assess(self, ctx: Context, challenge_num: int):
"""
Gets information about a specific CyberStart Assess level and challenge.
"""
NO_HINTS_MSG = f"**:warning: Remember, other people can't give hints after challenge {HINTS_LIMIT}**"
# Gather Assess data from JSON file.
with open("cdbot/data/assess.json") as f:
assess_docs = load(f)
if not 0 < challenge_num <= len(assess_docs):
await ctx.send("Invalid challenge number!")
else:
# Select the needed challenge
challenge_raw = assess_docs[challenge_num - 1]
challenge_title = challenge_raw["title"]
challenge_difficulty = challenge_raw["difficulty"]
challenge_text = challenge_raw["description"]
if challenge_num > HINTS_LIMIT:
challenge_text = NO_HINTS_MSG + "\n" + challenge_text
embed = Embed(
title=f"CyberStart Assess Challenge {challenge_num} - {challenge_title}",
description=challenge_text,
colour=0x4262F4,
url=f"https://assess.joincyberdiscovery.com/challenge-{challenge_num:02d}",
)
embed.set_author(name="Cyber Discovery", icon_url=CYBERDISC_ICON_URL)
embed.set_footer(text=f"Difficulty: {challenge_difficulty}")
await ctx.send(embed=embed)
示例4: vote
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def vote(self, ctx: Context, title: str, *options: str) -> None:
"""
Build a quick voting poll with matching reactions with the provided options.
A maximum of 20 options can be provided, as Discord supports a max of 20
reactions on a single message.
"""
if len(options) < 2:
raise BadArgument("Please provide at least 2 options.")
if len(options) > 20:
raise BadArgument("I can only handle 20 options!")
codepoint_start = 127462 # represents "regional_indicator_a" unicode value
options = {chr(i): f"{chr(i)} - {v}" for i, v in enumerate(options, start=codepoint_start)}
embed = Embed(title=title, description="\n".join(options.values()))
message = await ctx.send(embed=embed)
for reaction in options:
await message.add_reaction(reaction)
示例5: wolfram_page_command
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def wolfram_page_command(self, ctx: Context, *, query: str) -> None:
"""
Requests a drawn image of given query.
Keywords worth noting are, "like curve", "curve", "graph", "pokemon", etc.
"""
pages = await get_pod_pages(ctx, self.bot, query)
if not pages:
return
embed = Embed()
embed.set_author(name="Wolfram Alpha",
icon_url=WOLF_IMAGE,
url="https://www.wolframalpha.com/")
embed.colour = Colours.soft_orange
await ImagePaginator.paginate(pages, ctx, embed)
示例6: _send_confirmation
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def _send_confirmation(
ctx: Context,
on_success: str,
reminder_id: str,
delivery_dt: t.Optional[datetime],
) -> None:
"""Send an embed confirming the reminder change was made successfully."""
embed = discord.Embed()
embed.colour = discord.Colour.green()
embed.title = random.choice(POSITIVE_REPLIES)
embed.description = on_success
footer_str = f"ID: {reminder_id}"
if delivery_dt:
# Reminder deletion will have a `None` `delivery_dt`
footer_str = f"{footer_str}, Due: {delivery_dt.strftime('%Y-%m-%dT%H:%M:%S')}"
embed.set_footer(text=footer_str)
await ctx.send(embed=embed)
示例7: search_command
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def search_command(self, ctx: Context, *, query: OffTopicName) -> None:
"""Search for an off-topic name."""
result = await self.bot.api_client.get('bot/off-topic-channel-names')
in_matches = {name for name in result if query in name}
close_matches = difflib.get_close_matches(query, result, n=10, cutoff=0.70)
lines = sorted(f"• {name}" for name in in_matches.union(close_matches))
embed = Embed(
title="Query results",
colour=Colour.blue()
)
if lines:
await LinePaginator.paginate(lines, ctx, embed, max_size=400, empty=False)
else:
embed.description = "Nothing found."
await ctx.send(embed=embed)
示例8: refresh_command
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def refresh_command(self, ctx: commands.Context) -> None:
"""Refresh inventories and send differences to channel."""
old_inventories = set(self.base_urls)
with ctx.typing():
await self.refresh_inventory()
# Get differences of added and removed inventories
added = ', '.join(inv for inv in self.base_urls if inv not in old_inventories)
if added:
added = f"+ {added}"
removed = ', '.join(inv for inv in old_inventories if inv not in self.base_urls)
if removed:
removed = f"- {removed}"
embed = discord.Embed(
title="Inventories refreshed",
description=f"```diff\n{added}\n{removed}```" if added or removed else ""
)
await ctx.send(embed=embed)
示例9: startup_greeting
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def startup_greeting(self) -> None:
"""Announce our presence to the configured devlog channel."""
await self.bot.wait_until_guild_available()
log.info("Bot connected!")
embed = Embed(description="Connected!")
embed.set_author(
name="Python Bot",
url="https://github.com/python-discord/bot",
icon_url=(
"https://raw.githubusercontent.com/"
"python-discord/branding/master/logos/logo_circle/logo_circle_large.png"
)
)
if not DEBUG_MODE:
await self.bot.get_channel(Channels.dev_log).send(embed=embed)
示例10: webhook_send
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def webhook_send(
self,
content: Optional[str] = None,
username: Optional[str] = None,
avatar_url: Optional[str] = None,
embed: Optional[Embed] = None,
) -> None:
"""Sends a message to the webhook with the specified kwargs."""
username = messages.sub_clyde(username)
try:
await self.webhook.send(content=content, username=username, avatar_url=avatar_url, embed=embed)
except discord.HTTPException as exc:
self.log.exception(
"Failed to send a message to the webhook",
exc_info=exc
)
示例11: send_header
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def send_header(self, msg: Message) -> None:
"""Sends a header embed with information about the relayed messages to the watch channel."""
user_id = msg.author.id
guild = self.bot.get_guild(GuildConfig.id)
actor = guild.get_member(self.watched_users[user_id]['actor'])
actor = actor.display_name if actor else self.watched_users[user_id]['actor']
inserted_at = self.watched_users[user_id]['inserted_at']
time_delta = self._get_time_delta(inserted_at)
reason = self.watched_users[user_id]['reason']
if isinstance(msg.channel, DMChannel):
# If a watched user DMs the bot there won't be a channel name or jump URL
# This could technically include a GroupChannel but bot's can't be in those
message_jump = "via DM"
else:
message_jump = f"in [#{msg.channel.name}]({msg.jump_url})"
footer = f"Added {time_delta} by {actor} | Reason: {reason}"
embed = Embed(description=f"{msg.author.mention} {message_jump}")
embed.set_footer(text=textwrap.shorten(footer, width=128, placeholder="..."))
await self.webhook_send(embed=embed, username=msg.author.display_name, avatar_url=msg.author.avatar_url)
示例12: list_watched_users
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def list_watched_users(self, ctx: Context, update_cache: bool = True) -> None:
"""
Gives an overview of the watched user list for this channel.
The optional kwarg `update_cache` specifies whether the cache should
be refreshed by polling the API.
"""
if update_cache:
if not await self.fetch_user_cache():
await ctx.send(f":x: Failed to update {self.__class__.__name__} user cache, serving from cache")
update_cache = False
lines = []
for user_id, user_data in self.watched_users.items():
inserted_at = user_data['inserted_at']
time_delta = self._get_time_delta(inserted_at)
lines.append(f"• <@{user_id}> (added {time_delta})")
lines = lines or ("There's nothing here yet.",)
embed = Embed(
title=f"{self.__class__.__name__} watched users ({'updated' if update_cache else 'cached'})",
color=Color.blue()
)
await LinePaginator.paginate(lines, ctx, embed, empty=False)
示例13: notify_pardon
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def notify_pardon(
user: UserObject,
title: str,
content: str,
icon_url: str = Icons.user_verified
) -> bool:
"""DM a user about their pardoned infraction and return True if the DM is successful."""
log.trace(f"Sending {user} a DM about their pardoned infraction.")
embed = discord.Embed(
description=content,
colour=Colours.soft_green
)
embed.set_author(name=title, icon_url=icon_url)
return await send_private_embed(user, embed)
示例14: send_infraction_list
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def send_infraction_list(
self,
ctx: Context,
embed: discord.Embed,
infractions: t.Iterable[utils.Infraction]
) -> None:
"""Send a paginated embed of infractions for the specified user."""
if not infractions:
await ctx.send(":warning: No infractions could be found for that query.")
return
lines = tuple(
self.infraction_to_string(infraction)
for infraction in infractions
)
await LinePaginator.paginate(
lines,
ctx=ctx,
embed=embed,
empty=True,
max_lines=3,
max_size=1000
)
示例15: receive_message
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Embed [as 别名]
def receive_message(self, content: str = None, *, regex: bool = True, dm=False, embed: Embed = None):
"""
Assert that the bot sends a message, and that it is the message we expect.
If a regex is passed, this method returns the match object against the content.
:param content The text or regex to match the message content against
:param regex Whether to interpret content checking fields as a regex
:param dm Whether it was a Direct Message that was received or not
:param embed An embed to check against
"""
request = await self.get_request()
channel = TEST_DMCHANNEL_ID if dm else TEST_CHANNEL_ID
assert request.method == "POST"
assert request.url.endswith(f"/channels/{channel}/messages")
return message_content_check(request, content, regex=regex, embed=embed)