How to use the discord.utils.get 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 Gr8z / Legend-Cogs / shop / shop.py View on Github external
async def _is_payday(self, member):
        server = member.server
        botcommander_roles = [discord.utils.get(server.roles, name=r) for r in ["Pro Payday"]]
        botcommander_roles = set(botcommander_roles)
        author_roles = set(member.roles)
        if len(author_roles.intersection(botcommander_roles)):
            return True
        else:
            return False
github henry232323 / RPGBot / cogs / economy.py View on Github external
"""Create a new lotto, with jackpot payout lasting time in seconds.
        Requires Bot Moderator or Bot Admin
        For example: `rp!lotto create MyLotto 5000 3600` will create a new lotto called MyLotto
        (rp!lotto enter MyLotto to join), which has a jackpot of 5000 and lasts 1 hour (3600 seconds)"""
        if ctx.guild.id not in self.bot.lotteries:
            self.bot.lotteries[ctx.guild.id] = dict()
        if name in self.bot.lotteries[ctx.guild.id]:
            await ctx.send(await _(ctx, "A lottery of that name already exists!"))
            return
        current = dict(jackpot=jackpot, players=list(), channel=ctx.channel.id)
        self.bot.lotteries[ctx.guild.id][name] = current
        await ctx.send(await _(ctx, "Lottery created!"))
        await asyncio.sleep(time)
        if name in self.bot.lotteries[ctx.guild.id]:
            if current["players"]:
                winner = discord.utils.get(ctx.guild.members, id=choice(current["players"]))

                async with self.bot.di.rm.lock(winner.id):
                    await self.bot.di.add_eco(winner, current["jackpot"])
                await ctx.send(
                    (await _(ctx, "Lottery {} is now over!\n{} won {}! Congratulations!")).format(name, winner.mention,
                                                                                                  current["jackpot"]))
            else:
                await ctx.send((await _(ctx, "Nobody entered {}! Its over now.")).format(name))
            del self.bot.lotteries[ctx.guild.id][name]
github Gr8z / Legend-Cogs / drafting / drafting.py View on Github external
eligible = optionalarguments.partition("eligible=")[2].partition(",")[0]
			optionalarguments = optionalarguments.replace(eligible, "")
			eligiblerole = discord.utils.get(ctx.message.server.roles, name=eligible)
			if eligiblerole == None:
				await self.bot.say("Error, creating Draft failed. Invalid eligible statement(needs to be role name)", delete_after=autodeletetime)
				return
		else:
			eligiblerole = ctx.message.server.default_role

		if "tag" in optionalarguments:
			tag = "True"
		else:
			tag = "False"

		if eligiblerole == ctx.message.server.default_role:
			drafterrole = discord.utils.get(ctx.message.server.roles, name="MM participant")
			if tag == "False":
				mention = ""
			else:
				mention = drafterrole.mention
		else:
			if tag == "False":
				mention = ""
			else:
				mention = eligiblerole.mention

		draftobj = Draft(size=size, eligible=eligiblerole.id, name=name, host=host.id)
		print("## Draft '"+draftobj.name+"' has been created by "+host.display_name)
		

		self.opendrafts.append(draftobj.id)
		participants = []
github EvieePy / EvieeBot / modules / pythonista.py View on Github external
async def raid_off(self, ctx):
        for member in ctx.guild.members:
            await member.remove_roles(discord.utils.get(ctx.guild.roles, name='muted'))

        self.raid = False
        await ctx.send('Raid Mode: Off')
github PapyrusThePlant / Scarecrow / cogs / admin.py View on Github external
async def unban(self, ctx, member, *, reason: utils.AuditLogReason):
        """Unbans a member by name or ID."""
        bans = await ctx.guild.bans()
        try:
            member_id = int(member, base=10)
        except ValueError:
            ban_entry = discord.utils.get(bans, user__name=member)
        else:
            ban_entry = discord.utils.get(bans, user__id=member_id)

        if not ban_entry:
            raise commands.BadArgument(f'Banned member "{member}" not found.')

        await ctx.guild.unban(ban_entry.user, reason=reason)
        await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
github Gr8z / Legend-Cogs / fmod / fmod.py View on Github external
async def on_channel_create(self, channel):
        """Run when new channels are created and set up role permissions"""
        if channel.is_private:
            return

        server = channel.server
        if server.id != "374596069989810176":
            return

        rolename = self.settingsload[server.id]['Mute Role']
        role = discord.utils.get(server.roles, name=rolename)
        if not role:
            return

        await self.setup_channel(channel, role)
github Gr8z / Legend-Cogs / fmod / fmod.py View on Github external
await self.bot.edit_role(role=poop_role,
                                                     name=role_name,
                                                     server=server)
                            try:
                                await self.bot.add_roles(member,
                                                         poop_role)
                            except discord.errors.Forbidden:
                                await self.bot.say("No permission to add roles")
                else:
                    pass
        # checks if denied from a channel and re-adds role
        for mid in self.warningsload[sid]:
            try:
                for warning_key, data in self.warningsload[server.id][mid]["Warnings"].items():
                    if data['Warning Number'] == 'Channel Denied':
                        role = discord.utils.get(server.roles, name=deniedrole)
                        await self.bot.add_roles(member, role)
                        break
            except:
                continue

        if member.id in self.warningsload[sid]:
            if 'User Muted' in self.warningsload[sid][member.id]:
                duration = self.warningsload[sid][member.id]['User Muted']['until'] - time.time()
                if duration > 0:
                    rolename = self.settingsload[server.id]['Mute Role']
                    role = discord.utils.get(member.server.roles, name=rolename)
                    await self.bot.add_roles(member, role)
                    if member.id not in self.handles[sid]:
                        self.schedule_unpunish(duration, member, reason)
github NullPxl / NullCTF / cogs / ctfs.py View on Github external
async def create(self, ctx, params):
        try:
            sconf = serverdb[str(gid) + 'CONF']
            scat = sconf.find_one({'name': "category_name"})['ctfcategory'] # scat means server category
        except:
            scat = "CTF"
            
        category = discord.utils.get(ctx.guild.categories, name=scat)
        if category == None: # Checks if category exists, if it doesn't it will create it.
            await guild.create_category(name=scat)
            category = discord.utils.get(ctx.guild.categories, name=scat)

        await guild.create_text_channel(name=params, category=category)        
        server = teamdb[str(gid)]
        name = params.replace(' ', '-').replace("'", "").lower() # Discord does this when creating text channels. 
        await guild.create_role(name=name, mentionable=True)         
        ctf_info = {'name': name, "text_channel": name}
        server.update({'name': name}, {"$set": ctf_info}, upsert=True)
github Gr8z / Legend-Cogs / brawlstars / brawlstars.py View on Github external
author = ctx.message.author

        profiletag = await self.tags.formatTag(profiletag)

        if not await self.tags.verifyTag(profiletag):
            return await self.bot.say("The ID you provided has invalid characters. Please try again.")

        await self.bot.type()

        allowed = False
        if member is None:
            allowed = True
        elif member.id == author.id:
            allowed = True
        else:
            botcommander_roles = [discord.utils.get(server.roles, name=r) for r in BOTCOMMANDER_ROLES]
            botcommander_roles = set(botcommander_roles)
            author_roles = set(author.roles)
            if len(author_roles.intersection(botcommander_roles)):
                allowed = True

        if not allowed:
            return await self.bot.say("You dont have enough permissions to set tags for others.")

        member = member or ctx.message.author

        try:
            profiledata = self.brawl.get_player(profiletag)

            checkUser = await self.tags.getUserBS(server.members, profiletag)
            if checkUser is not None:
                return await self.bot.say("Error, This Player ID is already linked with **" + checkUser.display_name + "**")
github corpnewt / CorpBot.py / CorpBot.py View on Github external
async def getstat(ctx, stat : str = None, member : discord.Member = None):
	"""Gets the value for a specific stat for the listed member (case-sensitive)."""
	if member == None:
		member = ctx.message.author

	if str == None:
		msg = 'Usage: `$getstat [stat] [member]`'
		await bot.send_message(ctx.message.channel, msg)
		return

	if type(member) is str:
		try:
			member = discord.utils.get(message.server.members, name=member)
		except:
			print("That member does not exist")
			return

	if member is None:
		msg = 'Usage: `$getstat [stat] [member]`'
		await bot.send_message(ctx.message.channel, msg)
		return

	try:
		newStat = getUserStat(member, ctx.message.author.server, globals.serverList, stat)
	except KeyError:
		msg = '"{}" is not a valid stat for {}'.format(stat, member.name)
		await bot.send_message(ctx.message.channel, msg)
		return