当前位置: 首页>>代码示例>>Python>>正文


Python discord.NotFound方法代码示例

本文整理汇总了Python中discord.NotFound方法的典型用法代码示例。如果您正苦于以下问题:Python discord.NotFound方法的具体用法?Python discord.NotFound怎么用?Python discord.NotFound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在discord的用法示例。


在下文中一共展示了discord.NotFound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: maybe_delete_messages

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def maybe_delete_messages(self, channel: TextChannel, messages: List[Message]) -> None:
        """Cleans the messages if cleaning is configured."""
        if AntiSpamConfig.clean_offending:
            # If we have more than one message, we can use bulk delete.
            if len(messages) > 1:
                message_ids = [message.id for message in messages]
                self.mod_log.ignore(Event.message_delete, *message_ids)
                await channel.delete_messages(messages)

            # Otherwise, the bulk delete endpoint will throw up.
            # Delete the message directly instead.
            else:
                self.mod_log.ignore(Event.message_delete, messages[0].id)
                try:
                    await messages[0].delete()
                except NotFound:
                    log.info(f"Tried to delete message `{messages[0].id}`, but message could not be found.") 
开发者ID:python-discord,项目名称:bot,代码行数:19,代码来源:antispam.py

示例2: _change_cooldown_role

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def _change_cooldown_role(self, member: discord.Member, coro_func: CoroutineFunc) -> None:
        """
        Change `member`'s cooldown role via awaiting `coro_func` and handle errors.

        `coro_func` is intended to be `discord.Member.add_roles` or `discord.Member.remove_roles`.
        """
        guild = self.bot.get_guild(constants.Guild.id)
        role = guild.get_role(constants.Roles.help_cooldown)
        if role is None:
            log.warning(f"Help cooldown role ({constants.Roles.help_cooldown}) could not be found!")
            return

        try:
            await coro_func(role)
        except discord.NotFound:
            log.debug(f"Failed to change role for {member} ({member.id}): member not found")
        except discord.Forbidden:
            log.debug(
                f"Forbidden to change role for {member} ({member.id}); "
                f"possibly due to role hierarchy"
            )
        except discord.HTTPException as e:
            log.error(f"Failed to change role for {member} ({member.id}): {e.status} {e.code}") 
开发者ID:python-discord,项目名称:bot,代码行数:25,代码来源:help_channels.py

示例3: help_cleanup

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def help_cleanup(bot: Bot, author: Member, message: Message) -> None:
    """
    Runs the cleanup for the help command.

    Adds the :trashcan: reaction that, when clicked, will delete the help message.
    After a 300 second timeout, the reaction will be removed.
    """
    def check(reaction: Reaction, user: User) -> bool:
        """Checks the reaction is :trashcan:, the author is original author and messages are the same."""
        return str(reaction) == DELETE_EMOJI and user.id == author.id and reaction.message.id == message.id

    await message.add_reaction(DELETE_EMOJI)

    try:
        await bot.wait_for("reaction_add", check=check, timeout=300)
        await message.delete()
    except TimeoutError:
        await message.remove_reaction(DELETE_EMOJI, bot.user)
    except NotFound:
        pass 
开发者ID:python-discord,项目名称:bot,代码行数:22,代码来源:help.py

示例4: convert

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def convert(self, ctx, argument):
        id_regex = re.compile(r'^(?:(?P<channel_id>[0-9]{15,21})-)?(?P<message_id>[0-9]{15,21})$')
        link_regex = re.compile(
            r'^https?://(?:(ptb|canary)\.)?discord(?:app)?\.com/channels/'
            r'(?:([0-9]{15,21})|(@me))'
            r'/(?P<channel_id>[0-9]{15,21})/(?P<message_id>[0-9]{15,21})/?$'
        )
        match = id_regex.match(argument) or link_regex.match(argument)
        if not match:
            raise BadArgument('Message "{msg}" not found.'.format(msg=argument))
        message_id = int(match.group("message_id"))
        channel_id = match.group("channel_id")
        message = ctx.bot._connection._get_message(message_id)
        if message:
            return message
        channel = ctx.bot.get_channel(int(channel_id)) if channel_id else ctx.channel
        if not channel:
            raise BadArgument('Channel "{channel}" not found.'.format(channel=channel_id))
        try:
            return await channel.fetch_message(message_id)
        except discord.NotFound:
            raise BadArgument('Message "{msg}" not found.'.format(msg=argument))
        except discord.Forbidden:
            raise BadArgument("Can't read messages in {channel}".format(channel=channel.mention)) 
开发者ID:Rapptz,项目名称:discord.py,代码行数:26,代码来源:converter.py

示例5: check_role_on_support_guild

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def check_role_on_support_guild(role_name):
    async def predicate(ctx):
        support_guild = ctx.bot.get_guild(ctx.config.support_guild)
        if support_guild is None:
            log.warning("Support Guild is unavailable")
            raise cmd.CommandError(
                "The support guild is currently unavailable. Please try again later."
            )

        try:
            member = await support_guild.fetch_member(ctx.author.id)
        except discord.NotFound:
            raise cmd.CommandError("You need to be on the support guild to use this command.")

        roles = filter(lambda r: r.name == role_name, member.roles)
        if len(list(roles)) == 0:
            raise cmd.CommandError(
                f"You are **missing** the `{role_name}` **role** on the support guild."
            )

        return True

    return predicate 
开发者ID:Xenon-Bot,项目名称:xenon,代码行数:25,代码来源:checks.py

示例6: _overwrites_from_json

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def _overwrites_from_json(self, json):
        overwrites = {}
        for union_id, overwrite in json.items():
            try:
                union = await self.guild.fetch_member(int(union_id))
            except discord.NotFound:
                roles = list(
                    filter(lambda r: r.id == self.id_translator.get(union_id), self.guild.roles))
                if len(roles) == 0:
                    continue

                union = roles[0]

            overwrites[union] = discord.PermissionOverwrite(**overwrite)

        return overwrites 
开发者ID:Xenon-Bot,项目名称:xenon,代码行数:18,代码来源:backups.py

示例7: item23

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def item23(self, ctx):
        """Buy a mechanical duck (40 exp)
        !shop 23"""
        message = ctx.message
        _ = self.bot._;
        language = await self.bot.db.get_pref(ctx.channel, "language")

        try:
            await ctx.message.delete()
        except discord.Forbidden:
            await self.bot.hint(ctx=ctx, message=_("If you ask a server admin to give me the `manage_message` permission, I will be able to delete that kind of shop commands ;)", language))
        except discord.NotFound:
            pass

        await self.bot.db.add_to_stat(message.channel, message.author, "exp", -40)
        await self.bot.send_message(ctx=ctx, force_pm=True, message=_(":money_with_wings: You prepared a mechanical duck on the channel for 40 exp. It's wrong, but so funny!", language))

        async def spawn_mech_duck():
            await asyncio.sleep(90)
            duck = await ducks.MechanicalDuck.create(self.bot, ctx.channel, user=ctx.message.author)
            await spawning.spawn_duck(self.bot, ctx.channel, instance=duck, ignore_event=True)

        asyncio.ensure_future(spawn_mech_duck()) 
开发者ID:DuckHunt-discord,项目名称:DHV3,代码行数:25,代码来源:shop.py

示例8: hackban

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def hackban(self, ctx, user_id: int):
        """Bans a user outside of the server."""
        author = ctx.message.author
        guild = author.guild

        user = guild.get_member(user_id)
        if user is not None:
            return await ctx.invoke(self.ban, user=user)

        try:
            await self.bot.http.ban(user_id, guild.id, 0)
            await ctx.message.edit(content=self.bot.bot_prefix + 'Banned user: %s' % user_id)
        except discord.NotFound:
            await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user. '
                               'Invalid user ID was provided.')
        except discord.errors.Forbidden:
            await ctx.message.edit(content=self.bot.bot_prefix + 'Could not ban user. Not enough permissions.') 
开发者ID:appu1232,项目名称:Discord-Selfbot,代码行数:19,代码来源:mod.py

示例9: emoji_get_value

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def emoji_get_value(self, message):
        content = message.content.split()
        if len(content) != 3:
            return await self.emoji_list_all_values(message.channel)

        emoji = content[2]
        if not is_unicode(emoji):
            try:
                emoji_id = int(emoji.split(':')[2][:-1])
                emoji = await message.channel.guild.fetch_emoji(emoji_id)
            except (ValueError, IndexError):
                await message.channel.send(msg.karma_get_format)
                return
            except discord.NotFound:
                await message.channel.send(msg.karma_emote_not_found)
                return

        val = self.repo.emoji_value_raw(emoji)

        if val is not None:
            await message.channel.send(utils.fill_message("karma_get", emote=str(emoji), value=str(val)))
        else:
            await message.channel.send(utils.fill_message("karma_get_emote_not_voted", emote=str(emoji))) 
开发者ID:Toaster192,项目名称:rubbergod,代码行数:25,代码来源:karma.py

示例10: has_invite

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def has_invite(ev, arguments):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param arguments:
    :type arguments:
    :return:
    :rtype:
    """
    invite_found = False
    for arg in arguments:
        triggers = ['discord.gg', 'discordapp.com']
        for trigger in triggers:
            if trigger in arg:
                try:
                    await ev.bot.fetch_invite(arg)
                    invite_found = True
                    break
                except discord.NotFound:
                    pass
    return invite_found 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:23,代码来源:dm_detection.py

示例11: send_board_msg

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def send_board_msg(message, board_msg, board_resp):
    """
    :param message:
    :type message: discord.Message
    :param board_msg:
    :type board_msg: discord.Message
    :param board_resp:
    :type board_resp: discord.Embed
    :return:
    :rtype: discord.Message
    """
    replaced = False
    if board_msg:
        try:
            await board_msg.edit(embed=board_resp)
        except discord.NotFound:
            board_msg = await message.channel.send(embed=board_resp)
            replaced = True
    else:
        board_msg = await message.channel.send(embed=board_resp)
        replaced = True
    if replaced:
        [await board_msg.add_reaction(num) for num in nums]
    return board_msg 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:26,代码来源:connectfour.py

示例12: send_hangman_msg

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def send_hangman_msg(message, hangman_msg, hangman_resp):
    """
    :param message:
    :type message: discord.Message
    :param hangman_msg:
    :type hangman_msg: discord.Message
    :param hangman_resp:
    :type hangman_resp: discord.Embed
    :return:
    :rtype: discord.Message
    """
    if hangman_msg:
        try:
            await hangman_msg.edit(embed=hangman_resp)
        except discord.NotFound:
            hangman_msg = await message.channel.send(embed=hangman_resp)
    else:
        hangman_msg = await message.channel.send(embed=hangman_resp)
    return hangman_msg 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:21,代码来源:hangman.py

示例13: message_search

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def message_search(lookup: int, message: discord.Message):
    """

    :param lookup:
    :type lookup:
    :param message:
    :type message:
    :return:
    :rtype:
    """
    try:
        msg = await message.channel.fetch_message(lookup)
    except discord.NotFound:
        msg = None
    if not msg:
        for channel in message.guild.channels:
            if isinstance(channel, discord.TextChannel):
                try:
                    msg = await channel.fetch_message(lookup)
                    break
                except (discord.Forbidden, discord.NotFound):
                    msg = None
    return msg 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:25,代码来源:quote.py

示例14: mute_checker

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def mute_checker(ev, pld):
    """
    :param ev: The event object referenced in the event.
    :type ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.MessagePayload
    """
    if pld.msg.guild:
        if isinstance(pld.msg.author, discord.Member):
            if pld.msg.author.id not in ev.bot.cfg.dsc.owners:
                if not pld.msg.author.permissions_in(pld.msg.channel).administrator:
                    mute_list = pld.settings.get('muted_users') or []
                    if pld.msg.author.id in mute_list:
                        try:
                            await pld.msg.delete()
                        except discord.Forbidden:
                            pass
                        except discord.NotFound:
                            pass 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:21,代码来源:mute_checker.py

示例15: autorole_control

# 需要导入模块: import discord [as 别名]
# 或者: from discord import NotFound [as 别名]
def autorole_control(_ev, pld):
    """
    :param _ev: The main event instance referenced.
    :type _ev: sigma.core.mechanics.event.SigmaEvent
    :param pld: The event payload data to process.
    :type pld: sigma.core.mechanics.payload.MemberPayload
    """
    curr_role_id = pld.settings.get('auto_role')
    if curr_role_id:
        curr_role = pld.member.guild.get_role(curr_role_id)
        if curr_role:
            timeout = pld.settings.get('auto_role_timeout')
            if timeout:
                await asyncio.sleep(timeout)
            try:
                await pld.member.add_roles(curr_role, reason='Appointed guild autorole.')
            except (discord.NotFound, discord.Forbidden):
                pass 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:20,代码来源:autorole_control.py


注:本文中的discord.NotFound方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。