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


Python discord.InvalidArgument方法代码示例

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


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

示例1: run

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def run(self) -> typing.Optional[Message]:
        """
        Starts the pagination session.

        Returns
        -------
        Optional[Message]
            If it's closed before running ends.
        """
        if not self.running:
            await self.show_page(self.current)
        while self.running:
            try:
                reaction, user = await self.ctx.bot.wait_for(
                    "reaction_add", check=self.react_check, timeout=self.timeout
                )
            except asyncio.TimeoutError:
                return await self.close(delete=False)
            else:
                action = self.reaction_map.get(reaction.emoji)
                await action()
            try:
                await self.base.remove_reaction(reaction, user)
            except (HTTPException, InvalidArgument):
                pass 
开发者ID:kyb3r,项目名称:modmail,代码行数:27,代码来源:paginator.py

示例2: add

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def add(self, ctx, name, url):
        await ctx.message.delete()
        try:
            response = requests.get(url)
        except (requests.exceptions.MissingSchema, requests.exceptions.InvalidURL, requests.exceptions.InvalidSchema, requests.exceptions.ConnectionError):
            return await ctx.send(self.bot.bot_prefix + "The URL you have provided is invalid.")
        if response.status_code == 404:
            return await ctx.send(self.bot.bot_prefix + "The URL you have provided leads to a 404.")
        try:
            emoji = await ctx.guild.create_custom_emoji(name=name, image=response.content)
        except discord.InvalidArgument:
            return await ctx.send(self.bot.bot_prefix + "Invalid image type. Only PNG, JPEG and GIF are supported.")
        await ctx.send(self.bot.bot_prefix + "Successfully added the emoji {0.name} <{1}:{0.name}:{0.id}>!".format(emoji, "a" if emoji.animated else "")) 
开发者ID:appu1232,项目名称:Discord-Selfbot,代码行数:15,代码来源:emoji.py

示例3: add_reaction

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def add_reaction(msg, reaction: discord.Reaction) -> bool:
        if reaction != "disable":
            try:
                await msg.add_reaction(reaction)
            except (discord.HTTPException, discord.InvalidArgument) as e:
                logger.warning("Failed to add reaction %s: %s.", reaction, e)
                return False
        return True 
开发者ID:kyb3r,项目名称:modmail,代码行数:10,代码来源:bot.py

示例4: connect

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def connect(self, channel):
        """
        Connect to a voice channel

        :param channel: The voice channel to connect to
        :return:
        """
        # We're using discord's websocket, not lavalink
        if not channel.guild == self.guild:
            raise InvalidArgument("The guild of the channel isn't the the same as the link's!")
        if channel.guild.unavailable:
            raise IllegalAction("Cannot connect to guild that is unavailable!")

        me = channel.guild.me
        permissions = me.permissions_in(channel)
        if not permissions.connect and not permissions.move_members:
            raise BotMissingPermissions(["connect"])

        self.set_state(State.CONNECTING)
        payload = {
            "op": 4,
            "d": {
                "guild_id": channel.guild.id,
                "channel_id": str(channel.id),
                "self_mute": False,
                "self_deaf": False
            }
        }

        await self.bot._connection._get_websocket(channel.guild.id).send_as_json(payload) 
开发者ID:initzx,项目名称:rewrite,代码行数:32,代码来源:lavalink.py

示例5: group_add

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def group_add(self, ctx: NabCtx, *, name: str):
        """Creates a new group for members to join.

        The group can be a new role that will be created with this command.
        If the name matches an existent role, that role will become joinable.

        You need `Manage Roles` permissions to use this command."""
        name = name.replace("\"", "")
        forbidden = ["add", "remove", "delete", "list"]
        converter = InsensitiveRole()
        try:
            role = await converter.convert(ctx, name)
        except commands.BadArgument:
            try:
                if name.lower() in forbidden:
                    raise discord.InvalidArgument()
                role = await ctx.guild.create_role(name=name, reason="Created joinable role")
            except discord.Forbidden:
                await ctx.error("I need `Manage Roles` permission to create a group.")
                return
            except discord.InvalidArgument:
                await ctx.error("Invalid group name.")
                return

        exists = await ctx.pool.fetchval("SELECT true FROM role_joinable WHERE role_id = $1", role.id)
        if exists:
            await ctx.error(f"Group `{role.name}` already exists.")
            return

        # Can't make joinable group a role higher than the owner's top role
        top_role: discord.Role = ctx.author.top_role
        if role >= top_role:
            await ctx.error("You can't make a group from a role higher or equals than your highest role.")
            return

        await ctx.pool.execute("INSERT INTO role_joinable(server_id, role_id) VALUES($1, $2)", ctx.guild.id, role.id)
        await ctx.success(f"Group `{role.name}` created successfully.") 
开发者ID:NabDev,项目名称:NabBot,代码行数:39,代码来源:roles.py

示例6: move_after

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def move_after(self, ctx, channel: discord.Channel, after_channel: discord.Channel):
        """Move channel after a channel."""
        try:
            await self.bot.move_channel(channel, after_channel.position + 1)
            await self.bot.say("Channel moved.")
        except (InvalidArgument, Forbidden, HTTPException) as err:
            await self.bot.say("Move channel failed. " + str(err)) 
开发者ID:smlbiobot,项目名称:SML-Cogs,代码行数:9,代码来源:channelmanager.py

示例7: rm_add

# 需要导入模块: import discord [as 别名]
# 或者: from discord import InvalidArgument [as 别名]
def rm_add(self, ctx, *args):
        """Add reactions to a message by message id.

        Add reactions to a specific message id
        [p]rm add 123456 :white_check_mark: :x: :zzz:

        Add reactions to the last message in channel
        [p]rm add :white_check_mark: :x: :zzz:
        """
        channel = ctx.message.channel

        if not len(args):
            await self.bot.send_cmd_help(ctx)
            return

        has_message_id = args[0].isdigit()

        emojis = args[1:] if has_message_id else args
        message_id = args[0] if has_message_id else None

        if has_message_id:
            try:
                message = await self.bot.get_message(channel, message_id)
            except discord.NotFound:
                await self.bot.say("Cannot find message with that id.")
                return
        else:
            # use the 2nd last message because the last message would be the command
            messages = []
            async for m in self.bot.logs_from(channel, limit=2):
                messages.append(m)

            # messages = [m async for m in self.bot.logs_from(channel, limit=2)]
            message = messages[1]

        for emoji in emojis:
            try:
                await self.bot.add_reaction(message, emoji)
            except discord.HTTPException:
                # reaction add failed
                pass
            except discord.Forbidden:
                await self.bot.say(
                    "I don’t have permission to react to that message.")
                break
            except discord.InvalidArgument:
                await self.bot.say("Invalid arguments for emojis")
                break

        await self.bot.delete_message(ctx.message) 
开发者ID:smlbiobot,项目名称:SML-Cogs,代码行数:52,代码来源:reactionmanager.py


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