本文整理汇总了Python中discord.Emoji方法的典型用法代码示例。如果您正苦于以下问题:Python discord.Emoji方法的具体用法?Python discord.Emoji怎么用?Python discord.Emoji使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类discord
的用法示例。
在下文中一共展示了discord.Emoji方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_emote
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def get_emote(emoji):
"""
Gets a specific emote by lookup.
:param emoji: The emote to get.
:type emoji: str or discord.Emoji
:return:
:rtype: (str, int)
"""
lookup, eid = emoji, None
if ':' in emoji:
# matches custom emote
server_match = re.search(r'<a?:(\w+):(\d+)>', emoji)
# matches global emote
custom_match = re.search(r':(\w+):', emoji)
if server_match:
lookup, eid = server_match.group(1), server_match.group(2)
elif custom_match:
lookup, eid = custom_match.group(1), None
else:
lookup, eid = emoji.split(':')
try:
eid = int(eid)
except (ValueError, TypeError):
eid = None
return lookup, eid
示例2: get_matching_emote
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def get_matching_emote(guild, emote):
"""
Gets a matching emote from the given guild.
:param guild: The guild to search.
:type guild: discord.Guild
:param emote: The full emote string to look for.
:type emote: str
:return:
:rtype: discord.Emoji
"""
emote_name = emote.split(':')[1]
matching_emote = None
for emote in guild.emojis:
if emote.name == emote_name:
matching_emote = emote
return matching_emote
示例3: make_emoji_data
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def make_emoji_data(emj):
"""
Makes a data dict for storage for a custom emoji.
:param emj: The emoji to store.
:type emj: discord.Emoji
:rtype: dict
"""
data = {
"available": emj.available,
"managed": emj.managed,
"name": emj.name,
"roles": [FetchHelper.make_role_data(role) for role in emj.roles],
"require_colons": emj.require_colons,
"animated": emj.animated,
"id": str(emj.id)
}
return data
示例4: set_emoji
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def set_emoji(
self, ctx: commands.Context, starboard: StarboardExists, emoji: Union[discord.Emoji, str]
) -> None:
"""
Set the emoji for the starboard
`<name>` is the name of the starboard to change the emoji for
`<emoji>` must be an emoji on the server or a default emoji
"""
guild = ctx.guild
if type(emoji) == discord.Emoji:
if emoji not in guild.emojis:
await ctx.send(_("That emoji is not on this guild!"))
return
self.starboards[ctx.guild.id][starboard.name].emoji = str(emoji)
await self._save_starboards(guild)
msg = _("{emoji} set for starboard {name}").format(emoji=emoji, name=starboard.name)
await ctx.send(msg)
示例5: remove
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def remove(self, ctx, emoji: discord.Emoji):
"""Remove a clickable emoji from each new message."""
config = await self.db.find_one({"_id": "role-config"})
if config is None:
return await ctx.send("There are no emoji set for this server.")
emoji_dict = config["emoji"]
try:
del emoji_dict[f"<:{emoji.name}:{emoji.id}>"]
except KeyError:
return await ctx.send("That emoji is not configured")
await self.db.update_one({"_id": "role-config"}, {"$set": {"emoji": emoji_dict}})
await ctx.send(f"I successfully deleted <:{emoji.name}:{emoji.id}>.")
示例6: add
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def add(self, ctx, emoji: discord.Emoji, role: discord.Role):
emote = emoji.name if emoji.id is None else emoji.id
if emote in self.roles:
updated = True
else:
updated = False
self.roles[emote] = role.id
await self.db.find_one_and_update(
{"_id": "config"}, {"$set": {"roles": self.roles}}, upsert=True
)
await ctx.send(
f"Successfully {'updated'if updated else 'pointed'} {emoji} towards {role.name}"
)
示例7: remove
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def remove(self, ctx, emoji: discord.Emoji):
"""Remove a role from the role reaction list"""
emote = emoji.name if emoji.id is None else emoji.id
if emote not in self.roles:
await ctx.send("The Given Emote Was Not Configured")
return
self.roles.pop(emote)
await self.db.find_one_and_update(
{"_id": "config"}, {"$set": {"roles": self.roles}}, upsert=True
)
await ctx.send(f"Removed {emoji} from rolereaction list")
return
示例8: convert
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def convert(self, ctx, argument):
match = self._get_id_match(argument) or re.match(r'<a?:[a-zA-Z0-9\_]+:([0-9]+)>$', argument)
result = None
bot = ctx.bot
guild = ctx.guild
if match is None:
# Try to get the emoji by name. Try local guild first.
if guild:
result = discord.utils.get(guild.emojis, name=argument)
if result is None:
result = discord.utils.get(bot.emojis, name=argument)
else:
emoji_id = int(match.group(1))
# Try to look up emoji by id.
if guild:
result = discord.utils.get(guild.emojis, id=emoji_id)
if result is None:
result = discord.utils.get(bot.emojis, id=emoji_id)
if result is None:
raise BadArgument('Emoji "{}" not found.'.format(argument))
return result
示例9: find_emoji
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def find_emoji(emoji: str, client: Client) -> Optional[Emoji]:
try:
for guild in client.guilds:
emojis = guild.emojis
res = next((x for x in emojis if x.name == emoji), None)
if res is not None:
return res
return None
except AttributeError:
return None
示例10: test_emoji
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def test_emoji(db_emoji: bytearray, server_emoji: Emoji):
try:
custom_emoji = int(db_emoji)
return custom_emoji == server_emoji.id
except ValueError:
return False
示例11: respond_with_emote
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def respond_with_emote(message, icon):
"""
Responds to a message with an emote reaction.
:type message: discord.Message
:type icon: discord.Emoji or str
:param message: The message to respond to with an emote.
:param icon: The emote to react with to the message.
:return:
"""
try:
await message.add_reaction(icon)
except discord.DiscordException:
pass
示例12: regional
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def regional(self, ctx, *, msg: str):
"""Convert a Text to emotes."""
regional_list = self.to_regionals(msg, False)
regional_output = []
for i in regional_list:
regional_output.append(" ")
if isinstance(i, discord.Emoji):
regional_output.append(str(i))
else:
regional_output.append(i)
await edit(ctx, content=''.join(regional_output))
示例13: try_add_reaction
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def try_add_reaction(self,
emoji: discord.Emoji,
message: discord.Message = None,
fallback_message=''
):
"""Try to add a reaction to the message. If it fails, send a message instead."""
if message is None:
message = self.message
try:
await message.add_reaction(strip_angle_brackets(emoji))
except discord.Forbidden:
await self.send(f'{emoji} {fallback_message}')
示例14: __eq__
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def __eq__(self, other):
return self.id == other.id and isinstance(other, (type(self), discord.PartialEmoji, discord.Emoji))
示例15: attempt_add_reaction
# 需要导入模块: import discord [as 别名]
# 或者: from discord import Emoji [as 别名]
def attempt_add_reaction(msg: discord.Message, reaction: typing.Union[str, discord.Emoji])\
-> typing.Optional[discord.Reaction]:
"""
Try to add a reaction to a message, ignoring it if it fails for any reason.
:param msg: The message to add the reaction to.
:param reaction: The reaction emoji, could be a string or `discord.Emoji`
:return: A `discord.Reaction` or None, depending on if it failed or not.
"""
try:
return await msg.add_reaction(reaction)
except discord.HTTPException:
pass