Python discord.Forbidden() Examples
The following are 30
code examples of discord.Forbidden().
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: admin.py From Squid-Plugins with MIT License | 6 votes |
def removerole(self, ctx, rolename, user: discord.Member=None): """Removes a role from user, defaults to author Role name must be in quotes if there are spaces.""" server = ctx.message.server author = ctx.message.author role = self._role_from_string(server, rolename) if role is None: await self.bot.say("Role not found.") return if user is None: user = author if role in user.roles: try: await self.bot.remove_roles(user, role) await self.bot.say("Role successfully removed.") except discord.Forbidden: await self.bot.say("I don't have permissions to manage roles!") else: await self.bot.say("User does not have that role.")
Example #2
Source File: quote.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: mute_checker.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: setusername.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
def setusername(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args: name_input = ' '.join(pld.args) try: await cmd.bot.user.edit(username=name_input) response = ok(f'Changed username to {name_input}.') except discord.Forbidden: response = error('I was unable to change my username.') else: response = error('Nothing inputted.') await pld.msg.channel.send(embed=response)
Example #5
Source File: converter.py From discord.py with MIT License | 6 votes |
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))
Example #6
Source File: help_channels.py From bot with MIT License | 6 votes |
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}")
Example #7
Source File: autorole_control.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: setavatar.py From apex-sigma-core with GNU General Public License v3.0 | 6 votes |
def setavatar(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.args or pld.msg.attachments: image_url = pld.msg.attachments[0].url if pld.msg.attachments else pld.args[0] try: try: async with aiohttp.ClientSession() as session: async with session.get(image_url) as image_response: img_data = await image_response.read() await cmd.bot.user.edit(avatar=img_data) response = ok('My avatar has been changed.') except aiohttp.InvalidURL: response = error('Invalid URL.') except discord.Forbidden: response = error('I was unable to change my avatar.') else: response = error('Give me a link or attach an image, please.') await pld.msg.channel.send(embed=response)
Example #9
Source File: massmove.py From refactored-cogs with Mozilla Public License 2.0 | 6 votes |
def _massmove(self, ctx, from_channel, to_channel): """Internal function: Massmove users to another voice channel""" # check if channels are voice channels. Or moving will be very... interesting... type_from = str(from_channel.type) type_to = str(to_channel.type) if type_from == 'text': await self.bot.say('{} is not a valid voice channel'.format(from_channel.name)) log.debug('SID: {}, from_channel not a voice channel'.format(from_channel.server.id)) elif type_to == 'text': await self.bot.say('{} is not a valid voice channel'.format(to_channel.name)) log.debug('SID: {}, to_channel not a voice channel'.format(to_channel.server.id)) else: try: log.debug('Starting move on SID: {}'.format(from_channel.server.id)) log.debug('Getting copy of current list to move') voice_list = list(from_channel.voice_members) for member in voice_list: await self.bot.move_member(member, to_channel) log.debug('Member {} moved to channel {}'.format(member.id, to_channel.id)) await asyncio.sleep(0.05) except discord.Forbidden: await self.bot.say('I have no permission to move members.') except discord.HTTPException: await self.bot.say('A error occured. Please try again')
Example #10
Source File: util.py From DueUtil with GNU General Public License v3.0 | 6 votes |
def say(channel, *args, **kwargs): if type(channel) is str: # Server/Channel id server_id, channel_id = channel.split("/") channel = get_server(server_id).get_channel(channel_id) if "client" in kwargs: client = kwargs["client"] del kwargs["client"] else: client = get_client(channel.server.id) if asyncio.get_event_loop() != client.loop: # Allows it to speak across shards client.run_task(say, *((channel,) + args), **kwargs) else: try: await client.send_message(channel, *args, **kwargs) except discord.Forbidden as send_error: raise SendMessagePermMissing(send_error)
Example #11
Source File: mod.py From Discord-Selfbot with GNU General Public License v3.0 | 6 votes |
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.')
Example #12
Source File: mod.py From Discord-Selfbot with GNU General Public License v3.0 | 6 votes |
def mute(self, ctx, *, user: str): """Chat mutes a user (if you have the permission).""" if ctx.invoked_subcommand is None: user = get_user(ctx.message, user) if user and user != self.bot.user: failed = [] channel_length = 0 for channel in ctx.message.guild.channels: if type(channel) != discord.channel.TextChannel: continue overwrites = channel.overwrites_for(user) overwrites.send_messages = False channel_length += 1 try: await channel.set_permissions(user, overwrite=overwrites) except discord.Forbidden: failed.append(channel) if failed and len(failed) < channel_length: await ctx.message.edit(content=self.bot.bot_prefix + "Muted user in {}/{} channels: {}".format(channel_length - len(failed), channel_length, user.mention)) elif failed: await ctx.message.edit(content=self.bot.bot_prefix + "Failed to mute user. Not enough permissions.") else: await ctx.message.edit(content=self.bot.bot_prefix + 'Muted user: %s' % user.mention) else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
Example #13
Source File: mod.py From Discord-Selfbot with GNU General Public License v3.0 | 6 votes |
def channel(self, ctx, *, user: str): user = get_user(ctx.message, user) if user: overwrites = ctx.message.channel.overwrites_for(user) is_empty = self.are_overwrites_empty(overwrites) try: if not is_empty: ctx.message.channel.set_permissions(user, overwrite=overwrites) else: await channel.set_permissions(user, overwrite=None) await channel.set_permissions(user, overwrite=overwrites) await ctx.message.edit(content=self.bot.bot_prefix + 'Unmuted user in this channel: %s' % user.mention) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Unable to unmute user. Not enough permissions.') else: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.')
Example #14
Source File: config.py From RemixBot with MIT License | 6 votes |
def on_member_join(self, m): config = await self.bot.db.config.find_one({'_id': str(m.guild.id)}) if not config: return try: type = config['welctype'] except KeyError: return if type is False: return channel = int(config['welcchannel']) msg = config['welc'] success = False i = 0 while not success: try: await self.bot.get_channel(channel).send(msg.format(name=m, server=m.guild, mention=m.mention, member=m, membercount=len(m.guild.members))) except (discord.Forbidden, AttributeError): i += 1 except IndexError: # the channel set doesn't allow remixbot to send messages pass else: success = True
Example #15
Source File: simpleembed.py From FlameCogs with MIT License | 6 votes |
def sendembed(self, ctx, color:Optional[discord.Color]=None, *, text): """ Send an embed. Use the optional parameter `color` to change the color of the embed. The embed will contain the text `text`. All normal discord formatting will work inside the embed. """ if color is None: color = await ctx.embed_color() embed = discord.Embed( description=text, color=color ) await ctx.send(embed=embed) try: await ctx.message.delete() except discord.Forbidden: pass
Example #16
Source File: marttools.py From predacogs with MIT License | 6 votes |
def servercount(self, ctx: commands.Context): """Send servers stats of the bot.""" msg = _( "{name} is running on `{shard_count}` {shards}.\n" "Serving `{servs}` servers (`{channels}` channels).\n" "For a total of `{users}` users (`{unique}` unique).\n" "(`{users}` visible now, `{real_total}` total)" ).format( name=ctx.bot.user.name, shard_count=humanize_number(self.bot.shard_count), shards=_("shards") if self.bot.shard_count > 1 else _("shard"), servs=humanize_number(len(self.bot.guilds)), channels=humanize_number(sum(len(s.channels) for s in self.bot.guilds)), users=humanize_number(sum(len(s.members) for s in self.bot.guilds)), unique=humanize_number(len(self.bot.users)), real_total=humanize_number(sum(s.member_count for s in self.bot.guilds)), ) try: em = discord.Embed(color=await ctx.embed_colour(), description=msg) await ctx.send(embed=em) except discord.Forbidden: await ctx.send(msg)
Example #17
Source File: admin.py From Squid-Plugins with MIT License | 6 votes |
def whisper(self, ctx, id, *, text): author = ctx.message.author target = discord.utils.get(self.bot.get_all_members(), id=id) if target is None: target = self.bot.get_channel(id) if target is None: target = self.bot.get_server(id) prefix = "Hello, you're getting a message from {} ({})".format( author.name, author.id) payload = "{}\n\n{}".format(prefix, text) try: for page in pagify(payload, delims=[" ", "\n"], shorten_by=10): await self.bot.send_message(target, box(page)) except discord.errors.Forbidden: log.debug("Forbidden to send message to {}".format(id)) except (discord.errors.NotFound, discord.errors.InvalidArgument): log.debug("{} not found!".format(id)) else: await self.bot.say("Done.")
Example #18
Source File: shop.py From DHV3 with GNU Affero General Public License v3.0 | 6 votes |
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())
Example #19
Source File: mod.py From Discord-Selfbot with GNU General Public License v3.0 | 6 votes |
def kick(self, ctx, user, *, reason=""): """Kicks a user (if you have the permission).""" user = get_user(ctx.message, user) if user: try: await user.kick(reason=reason) return_msg = "Kicked user `{}`".format(user.mention) if reason: return_msg += " for reason `{}`".format(reason) return_msg += "." await ctx.message.edit(content=self.bot.bot_prefix + return_msg) except discord.Forbidden: await ctx.message.edit(content=self.bot.bot_prefix + 'Could not kick user. Not enough permissions.') else: return await ctx.message.edit(content=self.bot.bot_prefix + 'Could not find user.') # TODO: Add reason with ban
Example #20
Source File: approvesuggestion.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def react_to_suggestion(bot: ApexSigma, suggestion: dict, reaction: str, delete: bool): """ :param bot: :type bot: :param suggestion: :type suggestion: :param reaction: :type reaction: :param delete: :type delete: """ sugg_cmd = bot.modules.commands.get('botsuggest') if sugg_cmd: if sugg_cmd.cfg.channel: sugg_chn = await bot.get_channel(sugg_cmd.cfg.channel, True) if sugg_chn: try: smsg = await sugg_chn.fetch_message(suggestion.get('message')) if smsg: if delete: await smsg.delete() else: await smsg.add_reaction(reaction) except (discord.Forbidden, discord.NotFound): pass
Example #21
Source File: custom_command.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def custom_command(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: prefix = ev.db.get_prefix(pld.settings) if pld.msg.content.startswith(prefix): if pld.msg.content != prefix and not pld.msg.content.startswith(prefix + ' '): cmd = pld.msg.content[len(prefix):].lower().split()[0] if cmd not in ev.bot.modules.commands and cmd not in ev.bot.modules.alts: perms = ServerCommandPermissions(ev, pld.msg) await perms.check_perms() if perms.permitted: custom_commands = pld.settings.get('custom_commands') if custom_commands is None: custom_commands = {} if cmd in custom_commands: delcmd = pld.settings.get('delete_commands') if delcmd: try: await pld.msg.delete() except (discord.NotFound, discord.Forbidden): pass cmd_text = custom_commands[cmd] img = False if cmd_text.startswith('http'): img_endings = ['.gif', '.png', '.jpg', '.jpeg'] for ending in img_endings: if cmd_text.endswith(ending): img = True break if img: response = discord.Embed().set_image(url=cmd_text) await pld.msg.channel.send(embed=response) else: response = command_message_parser(pld.msg, cmd_text) await pld.msg.channel.send(escape_mentions(response, pld.msg.guild)) log_command_usage(ev.log, pld.msg, cmd)
Example #22
Source File: syncinvites.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def syncinvites(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ try: invites = await pld.msg.guild.invites() except discord.Forbidden: invites = [] await update_invites(pld.msg.guild, invites) bound_invites = pld.settings.get('bound_invites') or {} keys_to_remove = [] for invite_code in bound_invites.keys(): find_code = discord.utils.find(lambda x: x.id == invite_code, invites) if not find_code: keys_to_remove.append(invite_code) if keys_to_remove: for key_to_remove in keys_to_remove: bound_invites.pop(key_to_remove) await cmd.db.set_guild_settings(pld.msg.guild.id, 'bound_invites', bound_invites) noresp = False if pld.args: if pld.args[0] == 'noresp': noresp = True if not noresp: inv_count = len(invites) response = ok(f'Synced {inv_count} invites.') await pld.msg.channel.send(embed=response)
Example #23
Source File: misc.py From RemixBot with MIT License | 5 votes |
def say(self, ctx, *, message: commands.clean_content()): '''Say something as the bot''' voted = await self.upvoted(ctx.author.id) if not voted: return await ctx.send(f'To use this command, you must upvote RemixBot here: https://discordbots.org/bot/{self.bot.user.id}') try: await ctx.message.delete() except discord.Forbidden: pass await ctx.send(message)
Example #24
Source File: scr_cleaner_clock.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def scr_clockwork(ev): """ :param ev: The event object referenced in the event. :type ev: sigma.core.mechanics.event.SigmaEvent """ while True: if ev.bot.is_ready(): # noinspection PyBroadException try: coll = ev.db[ev.db.db_nam].ServerSettings colored_guild_docs = await coll.find({'color_roles': True}).to_list(None) guild_ids = [gdoc.get('server_id') for gdoc in colored_guild_docs] guilds = [] for gid in guild_ids: guild = await ev.bot.get_guild(gid, fetched=False) if guild: guilds.append(guild) for guild in guilds: scr_roles = [rl for rl in guild.roles if rl.name.startswith('SCR-')] for scrr in scr_roles: scrr_members = [scrm for scrm in scrr.members if not scrm.bot] if not scrr_members: try: await scrr.delete() ev.log.info(f'Deleted {scrr.name} [{scrr.id}] on {guild.name} [{guild.id}]') except (discord.Forbidden, discord.NotFound, discord.ClientException): pass await asyncio.sleep(5) except Exception: pass await asyncio.sleep(300)
Example #25
Source File: approvesuggestion.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def approvesuggestion(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if len(pld.args) >= 3: token, title, description = parse_approval(pld.args) suggestion = await cmd.db[cmd.db.db_nam].Suggestions.find_one({'suggestion.id': token}) if suggestion: await react_to_suggestion(cmd.bot, suggestion, '✅', False) make_issue = False if title.lower().startswith('noissue') else True title = title if make_issue else title.partition(' ')[2] gl_desc = make_gl_suggestion(token, description, suggestion) gl_issue_url = None if cmd.cfg.token and cmd.cfg.project and make_issue: gl_issue_url = await submit_gl_issue(cmd.cfg.token, cmd.cfg.project, title, gl_desc) athr = await cmd.bot.get_user(suggestion.get('user', {}).get('id')) if athr: to_user = ok(f'Suggestion {token} approved by {pld.msg.author.display_name}.') if gl_issue_url: to_user_desc = 'Your suggestion was approved, you can view its status and details [here]' to_user_desc += f'({gl_issue_url}). If you need info, the support server is in the help command.' else: to_user_desc = f'```md\n{gl_desc}\n```' to_user.description = to_user_desc try: await athr.send(embed=to_user) response = ok(f'Suggestion {token} approved.') except (discord.Forbidden, discord.NotFound): response = ok(f'Suggestion {token} approved, but delivery to author failed.') else: response = ok(f'Suggestion {token} approved, but the author was not found.') else: response = error('No suggestion entry with that ID was found.') else: response = error('Not enough arguments.') await pld.msg.channel.send(embed=response)
Example #26
Source File: stickyroles.py From 26-Cogs with GNU General Public License v3.0 | 5 votes |
def on_member_join(self, member): server = member.server if server.id not in self.db: return settings = self.db[server.id] if member.id not in settings["to_reapply"]: return to_add = [] for role_id in settings["to_reapply"][member.id]: if role_id not in settings["sticky_roles"]: continue role = discord.utils.get(server.roles, id=role_id) if role: to_add.append(role) del settings["to_reapply"][member.id] if to_add: try: await self.bot.add_roles(member, *to_add) except discord.Forbidden: print("Failed to add roles to {} ({})\n{}\n" "I lack permissions to do that." "".format(member, member.id, to_add)) except discord.HTTPException as e: print("Failed to add roles to {} ({})\n{}\n" "{}" "".format(member, member.id, to_add, e)) self.save()
Example #27
Source File: verification.py From bot with MIT License | 5 votes |
def accept_command(self, ctx: Context, *_) -> None: # We don't actually care about the args """Accept our rules and gain access to the rest of the server.""" log.debug(f"{ctx.author} called !accept. Assigning the 'Developer' role.") await ctx.author.add_roles(Object(constants.Roles.verified), reason="Accepted the rules") try: await ctx.author.send(WELCOME_MESSAGE) except Forbidden: log.info(f"Sending welcome message failed for {ctx.author}.") finally: log.trace(f"Deleting accept message by {ctx.author}.") with suppress(NotFound): self.mod_log.ignore(constants.Event.message_delete, ctx.message.id) await ctx.message.delete()
Example #28
Source File: admin.py From Squid-Plugins with MIT License | 5 votes |
def selfrole_remove(self, ctx, *, rolename): """Allows users to remove their own roles Configurable using `adminset`""" server = ctx.message.server author = ctx.message.author role_names = self._get_selfrole_names(server) if role_names is None: await self.bot.say("I have no user settable roles for this" " server.") return f = self._role_from_string roles = [f(server, r) for r in role_names if r is not None] role_to_remove = self._role_from_string(server, rolename, roles=roles) try: await self.bot.remove_roles(author, role_to_remove) except discord.errors.Forbidden: log.debug("{} just tried to remove a role but I was" " forbidden".format(author.name)) await self.bot.say("I don't have permissions to do that.") except AttributeError: # role_to_remove is NoneType log.debug("{} not found as removeable on {}".format(rolename, server.id)) await self.bot.say("That role isn't user removeable.") else: log.debug("Role {} removed from {} on {}".format(rolename, author.name, server.id)) await self.bot.say("Role removed.")
Example #29
Source File: declinesuggestion.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def declinesuggestion(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if len(pld.args) >= 2: token = pld.args[0].lower() reason = ' '.join(pld.args[1:]) suggestion = await cmd.db[cmd.db.db_nam].Suggestions.find_one({'suggestion.id': token}) if suggestion: delete = True if reason.lower().startswith('deleted') else False await react_to_suggestion(cmd.bot, suggestion, '⛔', delete) athr = await cmd.bot.get_user(suggestion.get('user', {}).get('id')) if athr: to_user = denied(f'Suggestion {token} declined by {pld.msg.author.display_name}.') to_user.description = reason try: await athr.send(embed=to_user) response = ok(f'Suggestion {token} declined.') except (discord.Forbidden, discord.NotFound): response = ok(f'Suggestion {token} declined, but delivery to author failed.') else: response = ok(f'Suggestion {token} declined, but the author was not found.') else: response = error('No suggestion entry with that ID was found.') else: response = error('Not enough arguments.') await pld.msg.channel.send(embed=response)
Example #30
Source File: bound_role_cacher.py From apex-sigma-core with GNU General Public License v3.0 | 5 votes |
def update_cache(guild): """ Updates the cache with fresh invites. :param guild: The discord guild of the invites. :type guild: discord.Guild """ try: invites = await guild.invites() except discord.Forbidden: invites = [] await update_invites(guild, invites)