Python discord.InvalidArgument() Examples
The following are 7
code examples of discord.InvalidArgument().
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: paginator.py From modmail with GNU Affero General Public License v3.0 | 6 votes |
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
Example #2
Source File: emoji.py From Discord-Selfbot with GNU General Public License v3.0 | 5 votes |
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 ""))
Example #3
Source File: lavalink.py From rewrite with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: roles.py From NabBot with Apache License 2.0 | 5 votes |
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.")
Example #5
Source File: channelmanager.py From SML-Cogs with MIT License | 5 votes |
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))
Example #6
Source File: bot.py From modmail with GNU Affero General Public License v3.0 | 4 votes |
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
Example #7
Source File: reactionmanager.py From SML-Cogs with MIT License | 4 votes |
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)