How to use the discord.utils function in discord

To help you get started, we’ve selected a few discord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lu-ci / apex-sigma-core / sigma / modules / owner_controls / information / ouserinformation.py View on Github external
async def ouserinformation(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:
        lookup = pld.args[0].lower()
        if '#' in lookup:
            uname = lookup.split('#')[0].lower()
            udisc = lookup.split('#')[1]
            target = discord.utils.find(lambda u: u.name.lower() == uname and u.discriminator == udisc, cmd.bot.users)
        else:
            try:
                target = await cmd.bot.get_user(int(lookup))
            except ValueError:
                target = None
        if target:
            user_color = await get_image_colors(user_avatar(target))
            response = discord.Embed(color=user_color)
            response.set_author(name=f'{target.display_name}\'s Information', icon_url=user_avatar(target))
            creation_time = arrow.get(target.created_at).format('DD. MMMM YYYY')
            user_text = f'Username: **{target.name}**#{target.discriminator}'
            user_text += f'\nID: **{target.id}**'
            user_text += f'\nBot User: **{target.bot}**'
            user_text += f'\nCreated: **{creation_time}**'
            presence = [g for g in cmd.bot.guilds if g.get_member(target.id)]
            response.add_field(name='User Info', value=user_text)
github strinking / futaba / futaba / navi / factory.py View on Github external
def build_navi_task(bot, storage):
    logger.debug("Creating NaviTask for %r", storage)
    causer = discord.utils.get(bot.users, id=storage.user_id)
    if causer is None:
        logger.debug(
            "Couldn't find causing user %d, returning dummy user", storage.user_id
        )
        causer = FakeUser(
            id=storage.user_id, name=int(storage.user_id), discriminator="0000"
        )

    guild = discord.utils.get(bot.guilds, id=storage.guild_id)
    if guild is None:
        raise ValueError(f"Unable to find guild with ID {storage.guild_id}")

    return TASK_BUILDERS[storage.task_type](bot, causer, guild, storage)
github MonikaDiscord / Monika / monika.py View on Github external
async def on_member_join(self, member):
        guild = member.guild
        channel = discord.utils.get(guild.channels, name="welcome")
        if channel:
            if member.id == 436351740787294208:
                await channel.send("Hi, Mon- wait.. What? Something isn't right here. Please go away. Please go away now. What is this? WHAT IS THIS? WHAT'S HAPPENING TO ME????")
            else:
                await channel.send(f"Hi, <@{member.id}>! Welcome to {guild.name}! I hope you have a good time here~")
github lu-ci / apex-sigma / sigma / plugins / moderation / movement / movelog / move_log_leave.py View on Github external
async def move_log_leave(ev, member):
    try:
        log_channel_id = ev.db.get_settings(member.guild.id, 'LoggingChannel')
    except:
        log_channel_id = None
    if log_channel_id:
        log_channel = discord.utils.find(lambda x: x.id == log_channel_id, member.guild.channels)
        if log_channel:
            response = discord.Embed(color=0xDB0000, timestamp=arrow.utcnow().datetime)
            response.set_author(name=f'A Member Has Left', icon_url=user_avatar(member))
            response.add_field(name='📤 Leaving Member', value=f'{member.mention}\n{member.name}#{member.discriminator}')
            new_acc, diff_msg = get_time_difference(member, leave=True)
            response.add_field(name='🕑 Member Joined', value=f'{diff_msg.title()}', inline=True)
            response.set_footer(text=f'UserID: {member.id}')
            await log_channel.send(embed=response)
        else:
            ev.db.set_settings(member.guild.id, 'LoggingChannel', None)
github Cog-Creators / Red-DiscordBot / cogs / trivia.py View on Github external
async def trivia_stop(self, ctx):
        """Stops an ongoing trivia session"""
        author = ctx.message.author
        server = author.server
        admin_role = self.bot.settings.get_server_admin(server)
        mod_role = self.bot.settings.get_server_mod(server)
        is_admin = discord.utils.get(author.roles, name=admin_role)
        is_mod = discord.utils.get(author.roles, name=mod_role)
        is_owner = author.id == self.bot.settings.owner
        is_server_owner = author == server.owner
        is_authorized = is_admin or is_mod or is_owner or is_server_owner

        session = self.get_trivia_by_channel(ctx.message.channel)
        if session:
            if author == session.starter or is_authorized:
                await session.end_game()
                await self.bot.say("Trivia stopped.")
            else:
                await self.bot.say("You are not allowed to do that.")
        else:
            await self.bot.say("There's no trivia session ongoing in this channel.")
github TrustyJAID / Trusty-cogs / retrigger / triggerhandler.py View on Github external
timestamp=ctx.message.created_at,
                    colour=await ctx.embed_colour(),
                    title=_("Triggers for {guild}").format(guild=ctx.guild.name),
                )
                em.set_author(name=author, icon_url=author.avatar_url)
                if trigger.created_at == 0:
                    em.set_footer(
                        text=_("Page {page}/{leng}").format(page=page, leng=len(trigger_list))
                    )
                else:
                    em.set_footer(
                        text=_("Page {page}/{leng} Created").format(
                            page=page, leng=len(trigger_list)
                        )
                    )
                    em.timestamp = discord.utils.snowflake_time(trigger.created_at)

                first = True
                for pages in pagify(info, page_length=1024):
                    if first:
                        em.description = pages
                        first = False
                    else:
                        em.add_field(name=_("Trigger info continued"), value=pages)
                msg_list.append(em)
            else:
                info += _("Regex: ") + box(trigger.regex.pattern[: 2000 - len(info)], lang="bf")
                msg_list.append(info)
            page += 1
        return msg_list
github lu-ci / apex-sigma-core / sigma / modules / moderation / server_settings / roles / role_groups / role_group_check.py View on Github external
async def role_group_check(_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.MemberUpdatePayload
    """
    before_role_ids = [role.id for role in pld.before.roles]
    added_role = discord.utils.find(lambda role: role.id not in before_role_ids, pld.after.roles)
    if added_role:
        role_groups = pld.settings.get('role_groups') or {}
        await appropriate_roles(pld.after, added_role, role_groups)
github lu-ci / apex-sigma-core / sigma / modules / core_functions / experience / experience_clock.py View on Github external
def add_exp(message, amount):
    global exp_storage
    storage_item = discord.utils.find(lambda x: x[0].id == message.author.id, exp_storage)
    curr_exp = storage_item[2] if storage_item else 0
    new_exp = curr_exp + amount
    exp_storage = list(filter(lambda x: x[0].id != message.author.id, exp_storage))
    exp_storage.append([message, new_exp])
github corpnewt / CorpBot.py / Cogs / Hw.py View on Github external
msg = '*{}* has no builds on file!  They can add some with the `{}newhw` command.'.format(DisplayName.name(memFromName), ctx.prefix)
				return await ctx.send(msg)
			
			# Must be the default build
			for build in buildList:
				if build['Main']:
					buildParts = build
					break

			if not buildParts:
				# Well... uh... no defaults
				msg = "I couldn't find that user/build combo..."
				return await ctx.send(msg)
		
		# At this point - we *should* have a user and a build
		p = discord.utils.escape_markdown(buildParts['Hardware'])
		msg = "__**{}'s {} (Raw Markdown):**__\n\n{}".format(DisplayName.name(memFromName), buildParts['Name'], p)
		await ctx.send(Utils.suppressed(ctx,msg))