Python discord 模块,Reaction() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用discord.Reaction()

项目:Tobo-Cogs    作者:Tobotimus    | 项目源码 | 文件源码
def _reaction_removed(self, reaction: discord.Reaction, user: discord.User):
        if self.setting_emojis: return # Don't change karma whilst adding/removing emojis
        server = reaction.message.server
        author = reaction.message.author
        if author == user: return # Users can't change their own karma
        emoji = reaction.emoji
        if isinstance(emoji, discord.Emoji):
            emoji = emoji.name
        else:
            emoji = name(emoji)
        try:
            if emoji == self.settings[server.id][UPVOTE]:
                self._add_karma(author.id, -1)
            elif emoji == self.settings[server.id][DOWNVOTE]:
                self._add_karma(author.id, 1)
        except:
            return
项目:Tobo-Cogs    作者:Tobotimus    | 项目源码 | 文件源码
def _reaction_added(self, reaction: discord.Reaction, user: discord.User):
        if self.setting_emojis: return # Don't change karma whilst adding/removing emojis
        server = reaction.message.server
        author = reaction.message.author
        if author == user: return # Users can't change their own karma
        emoji = reaction.emoji
        if isinstance(emoji, discord.Emoji):
            emoji = emoji.name
        else:
            emoji = name(emoji)
        try:
            if emoji == self.settings[server.id][UPVOTE]:
                self._add_karma(author.id, 1)
            elif emoji == self.settings[server.id][DOWNVOTE]:
                self._add_karma(author.id, -1)
        except:
            return
项目:dogbot    作者:slice    | 项目源码 | 文件源码
def confirm(self, *, title: str, description: str, confirm_cancellation=False):
        """Confirms something."""
        embed = discord.Embed(color=discord.Color.red(), title=title, description=description)
        confirmation = await self.send(embed=embed)

        for tick in (self.bot.tick(tick_type, raw=True, guild=self.guild) for tick_type in ('green', 'red')):
            await confirmation.add_reaction(tick)

        while True:
            def check(reaction: discord.Reaction, adder: discord.User) -> bool:
                return adder == self.message.author and reaction.message.id == confirmation.id

            # wait for a reaction
            reaction, adder = await self.bot.wait_for('reaction_add', check=check)

            # ignore regular emoji
            if isinstance(reaction.emoji, str):
                continue

            if reaction.emoji.id == 318595000311087105:
                await confirmation.delete()
                return True
            elif reaction.emoji.id == 318595010385674240:
                await confirmation.delete()
                if confirm_cancellation:
                    await self.send('Operation cancelled.')
                return False
项目:Tobo-Cogs    作者:Tobotimus    | 项目源码 | 文件源码
def _set_reaction(self, server, reaction: discord.Reaction, type):
        emoji = reaction.emoji
        if isinstance(emoji, discord.Emoji):
            emoji = emoji.name
        else:
            emoji = name(emoji)
        if server.id not in self.settings: 
            self.settings[server.id] = {}
        self.settings[server.id][type] = emoji
        dataIO.save_json(SETTINGS_PATH, self.settings)
项目:Addon    作者:GitAcrown    | 项目源码 | 文件源码
def check(self, reaction: discord.Reaction, user: discord.Member):
        return not user.bot
项目:modis    作者:Infraxion    | 项目源码 | 文件源码
def on_reaction_add(reaction, user):
    """The on_message event handler for this module

    Args:
        reaction (discord.Reaction): Input reaction
        user (discord.User): The user that added the reaction
    """

    # Simplify reaction info
    server = reaction.message.server
    emoji = reaction.emoji

    data = datatools.get_data()

    if not data["discord"]["servers"][server.id][_data.modulename]["activated"]:
        return

    # Commands section
    if user != reaction.message.channel.server.me:
        if server.id not in _data.cache or _data.cache[server.id].state == 'destroyed':
            return

        try:
            valid_reaction = reaction.message.id == _data.cache[server.id].embed.sent_embed.id
        except AttributeError:
            pass
        else:
            if valid_reaction:
                # Remove reaction
                try:
                    await client.remove_reaction(reaction.message, emoji, user)
                except discord.errors.NotFound:
                    pass
                except discord.errors.Forbidden:
                    pass

                # Commands
                if emoji == "?":
                    await _data.cache[server.id].toggle()
                if emoji == "?":
                    await _data.cache[server.id].stop()
                if emoji == "?":
                    await _data.cache[server.id].skip("1")
                if emoji == "?":
                    await _data.cache[server.id].rewind("1")
                if emoji == "??":
                    await _data.cache[server.id].shuffle()
                if emoji == "??":
                    await _data.cache[server.id].setvolume('-')
                if emoji == "??":
                    await _data.cache[server.id].setvolume('+')