Python discord.PartialEmoji() Examples

The following are 7 code examples of discord.PartialEmoji(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module discord , or try the search function .
Example #1
Source File: reactions.py    From RulesBot with MIT License 6 votes vote down vote up
def emote_reaction_handle(self, event: RawReactionActionEvent, handle):
        message_id: str = str(event.message_id)
        emoji: PartialEmoji = event.emoji
        if emoji.is_unicode_emoji():
            emoji = str(emoji)
        else:
            emoji = emoji.id
        guild: Guild = self.bot.get_guild(event.guild_id)
        user: Member = guild.get_member(event.user_id)
        action_query: ModelSelect = ReactionAction.select().where((ReactionAction.emoji == emoji) &
                                                                  (ReactionAction.message_id == message_id))
        if not action_query.exists():
            return
        action: ReactionAction = action_query.get()
        role_id = action.role_id
        role: Role = discord.utils.get(guild.roles,
                                       id=int(role_id))
        if role is None:
            print('Role not found.')
            return
        await handle(user, role, reason='Self roles') 
Example #2
Source File: converter.py    From discord.py with MIT License 5 votes vote down vote up
def convert(self, ctx, argument):
        match = re.match(r'<(a?):([a-zA-Z0-9\_]+):([0-9]+)>$', argument)

        if match:
            emoji_animated = bool(match.group(1))
            emoji_name = match.group(2)
            emoji_id = int(match.group(3))

            return discord.PartialEmoji.with_state(ctx.bot._connection, animated=emoji_animated, name=emoji_name,
                                                   id=emoji_id)

        raise BadArgument('Couldn\'t convert "{}" to PartialEmoji.'.format(argument)) 
Example #3
Source File: emote.py    From EmoteCollector with GNU Affero General Public License v3.0 5 votes vote down vote up
def url(id, *, animated: bool = False):
	"""Convert an emote ID to the image URL for that emote."""
	return str(discord.PartialEmoji(animated=animated, name='', id=id).url)

# remove when d.py v1.3.0 drops 
Example #4
Source File: emote.py    From EmoteCollector with GNU Affero General Public License v3.0 5 votes vote down vote up
def steal_these(self, context, *emotes):
		"""Steal a bunch of custom emotes."""

		# format is: {(order, error_message_format_string): emotes_that_had_that_error}
		# no error: key=None
		# HTTP error: key=HTTP status code
		messages = {}
		# we could use *emotes: discord.PartialEmoji here but that would require spaces between each emote.
		# and would fail if any arguments were not valid emotes
		for match in re.finditer(utils.lexer.t_CUSTOM_EMOTE, ''.join(emotes)):
			animated, name, id = match.groups()
			image_url = utils.emote.url(id, animated=animated)
			async with context.typing():
				arg = fr'\:{name}:'

				try:
					emote = await self.add_from_url(name, image_url, context.author.id)
				except BaseException as error:
					messages.setdefault(self._humanize_errors(error), []).append(arg)
				else:
					messages.setdefault((0, _('**Successfully created:**')), []).append(str(emote))

		if not messages:
			return await context.send(_('Error: no existing custom emotes were provided.'))

		messages = sorted(messages.items())
		message = self._format_errors(messages)
		await context.send(message) 
Example #5
Source File: db.py    From EmoteCollector with GNU Affero General Public License v3.0 5 votes vote down vote up
def __eq__(self, other):
		return self.id == other.id and isinstance(other, (type(self), discord.PartialEmoji, discord.Emoji)) 
Example #6
Source File: serverstats.py    From Trusty-cogs with MIT License 5 votes vote down vote up
def emoji(
        self, ctx: commands.Context, emoji: Union[discord.Emoji, discord.PartialEmoji, str]
    ) -> None:
        """
            Post a large size emojis in chat
        """
        await ctx.channel.trigger_typing()
        if type(emoji) in [discord.PartialEmoji, discord.Emoji]:
            d_emoji = cast(discord.Emoji, emoji)
            ext = "gif" if d_emoji.animated else "png"
            url = "https://cdn.discordapp.com/emojis/{id}.{ext}?v=1".format(id=d_emoji.id, ext=ext)
            filename = "{name}.{ext}".format(name=d_emoji.name, ext=ext)
        else:
            try:
                """https://github.com/glasnt/emojificate/blob/master/emojificate/filter.py"""
                cdn_fmt = "https://twemoji.maxcdn.com/2/72x72/{codepoint:x}.png"
                url = cdn_fmt.format(codepoint=ord(str(emoji)))
                filename = "emoji.png"
            except TypeError:
                await ctx.send(_("That doesn't appear to be a valid emoji"))
                return
        try:
            async with aiohttp.ClientSession() as session:
                async with session.get(url) as resp:
                    image = BytesIO(await resp.read())
        except Exception:
            await ctx.send(_("That doesn't appear to be a valid emoji"))
            return
        file = discord.File(image, filename=filename)
        await ctx.send(file=file) 
Example #7
Source File: awaiter.py    From RulesBot with MIT License 4 votes vote down vote up
def emoji_reaction(self, text: str) -> PartialEmoji:
        await self.ctx.send(
            embed=Embed(
                color=Color.blurple(),
                description=text))

        def check(reaction: Reaction, user: User):
            message: Message = reaction.message
            return message.channel == self.message.channel and user.id == self.message.author.id

        try:
            reaction, user = await self.bot.wait_for('reaction_add', check=check, timeout=30)
            return reaction
        except asyncio.TimeoutError:
            raise AwaitTimedOut