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


Python discord.Invite方法代码示例

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


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

示例1: on_invite_create

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def on_invite_create(self, invite: discord.Invite):
		guild = invite.guild
		if guild.id in self.bot.premium_guilds:
			await self.load_invites(guild.id)
		if not isinstance(guild, discord.Guild):
			return
		logch = self.bot.get_config(guild).get('log.action')
		if logch:
			embed = discord.Embed(color=discord.Color.green(), timestamp=datetime.datetime.now(datetime.timezone.utc), description=f'**An invite was created**')
			embed.set_author(name=guild.name, icon_url=str(guild.icon_url_as(static_format='png', size=2048)))
			embed.add_field(name='Invite Code', value=invite.code, inline=False)
			embed.add_field(name='Max Uses', value=invite.max_uses, inline=False)
			embed.add_field(name='Temporary', value=invite.temporary, inline=False)
			if invite.temporary:
				delta = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(seconds=invite.max_age)
				if isinstance(delta, datetime.timedelta):
					embed.add_field(name='Expires in', value=humanfriendly.format_timespan(delta), inline=False)
			if isinstance(invite.channel, discord.abc.GuildChannel):
				embed.add_field(name='Channel', value=f'#{invite.channel.name}({invite.channel.id})', inline=False)
			if invite.inviter:
				embed.set_footer(text=f'Created by: {invite.inviter} ({invite.inviter.id})')
			try:
				await logch.send(embed=embed)
			except Exception:
				pass 
开发者ID:FireDiscordBot,项目名称:bot,代码行数:27,代码来源:settings.py

示例2: on_invite_delete

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def on_invite_delete(self, invite: discord.Invite):
		guild = invite.guild
		if guild.id in self.bot.premium_guilds:
			await self.load_invites(guild.id)
		if not isinstance(guild, discord.Guild):
			return
		whodidit = None
		async for a in guild.audit_logs(action=discord.AuditLogAction.invite_delete, limit=1):
			if a.target.code == invite.code:
				whodidit = a.user
		logch = self.bot.get_config(guild).get('log.action')
		if logch:
			embed = discord.Embed(color=discord.Color.red(), timestamp=datetime.datetime.now(datetime.timezone.utc), description=f'**An invite was deleted**')
			embed.set_author(name=guild.name, icon_url=str(guild.icon_url_as(static_format='png', size=2048)))
			embed.add_field(name='Invite Code', value=invite.code, inline=False)
			if isinstance(invite.channel, discord.abc.GuildChannel):
				embed.add_field(name='Channel', value=f'#{invite.channel.name}({invite.channel.id})', inline=False)
			if whodidit:
				embed.set_footer(text=f'Deleted by: {whodidit} ({whodidit.id})')
			try:
				await logch.send(embed=embed)
			except Exception:
				pass 
开发者ID:FireDiscordBot,项目名称:bot,代码行数:25,代码来源:settings.py

示例3: convert

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def convert(self, ctx, argument):
        try:
            invite = await ctx.bot.fetch_invite(argument)
            return invite
        except Exception as exc:
            raise BadArgument('Invite is invalid or expired') from exc 
开发者ID:Rapptz,项目名称:discord.py,代码行数:8,代码来源:converter.py

示例4: update_invites

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def update_invites(guild, invites):
    """
    :param guild: The guild that the invites are from.
    :type guild: discord.Guild
    :param invites: The list of invites.
    :type invites: list[discord.Invite]
    """
    cache_key = f'invite_cache_{guild.id}'
    cache = await invite_cache.get_cache(cache_key) or {}
    cache.update({guild.id: invites})
    await invite_cache.set_cache(cache_key, cache) 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:13,代码来源:bound_role_cacher.py

示例5: get_changed_invite

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def get_changed_invite(guild_id, bound_list, invites):
    """
    Checks for invite count changes to get the one that triggered.
    :param guild_id: The ID of the guild.
    :type guild_id: int
    :param bound_list: A list of bound roles.
    :type bound_list: list
    :param invites: A list of the guild's invites.
    :type invites: list[discord.Invite]
    :return:
    :rtype: discord.Invite
    """
    invite = None
    cache_key = f'invite_cache_{guild_id}'
    cache = await invite_cache.get_cache(cache_key) or {}
    cached = cache.get(guild_id)
    if cached is None:
        cached = []
    cache.update({guild_id: invites})
    await invite_cache.set_cache(cache_key, cache)
    if invites is None:
        invites = []
    if invites:
        for cached_inv in cached:
            for curr_inv in invites:
                if cached_inv.id == curr_inv.id:
                    if cached_inv.uses != curr_inv.uses:
                        if curr_inv.id in bound_list:
                            invite = curr_inv
                            break
    return invite 
开发者ID:lu-ci,项目名称:apex-sigma-core,代码行数:33,代码来源:bound_role_cacher.py

示例6: on_member_join

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def on_member_join(self, member: discord.Member):
        guild = member.guild
        if guild.id not in self.settings:
            return
        if not self.settings[guild.id]["user_join"]["enabled"]:
            return
        # if not await self.config.guild(guild).user_join.enabled():
        # return
        try:
            channel = await self.modlog_channel(guild, "user_join")
        except RuntimeError:
            return
        embed_links = (
            channel.permissions_for(guild.me).embed_links
            and self.settings[guild.id]["user_join"]["embed"]
        )
        time = datetime.datetime.utcnow()
        users = len(guild.members)
        # https://github.com/Cog-Creators/Red-DiscordBot/blob/develop/cogs/general.py
        since_created = (time - member.created_at).days
        user_created = member.created_at.strftime("%d %b %Y %H:%M")

        created_on = "{}\n({} days ago)".format(user_created, since_created)

        possible_link = await self.get_invite_link(guild)
        if embed_links:
            embed = discord.Embed(
                description=member.mention,
                colour=await self.get_event_colour(guild, "user_join"),
                timestamp=member.joined_at if member.joined_at else datetime.datetime.utcnow(),
            )
            embed.add_field(name=_("Total Users:"), value=str(users))
            embed.add_field(name=_("Account created on:"), value=created_on)
            embed.set_footer(text=_("User ID: ") + str(member.id))
            embed.set_author(
                name=_("{member} ({m_id}) has joined the guild").format(
                    member=member, m_id=member.id
                ),
                url=member.avatar_url,
                icon_url=member.avatar_url,
            )
            if possible_link:
                embed.add_field(name=_("Invite Link"), value=possible_link)
            embed.set_thumbnail(url=member.avatar_url)
            await channel.send(embed=embed)
        else:
            time = datetime.datetime.utcnow()
            msg = _(
                "{emoji} `{time}` **{member}**(`{m_id}`) "
                "joined the guild. Total members: {users}"
            ).format(
                emoji=self.settings[guild.id]["user_join"]["emoji"],
                time=time.strftime("%H:%M:%S"),
                member=member,
                m_id=member.id,
                users=users,
            )
            await channel.send(msg) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:60,代码来源:eventmixin.py

示例7: on_invite_create

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def on_invite_create(self, invite: discord.Invite) -> None:
        """
            New in discord.py 1.3
        """
        guild = invite.guild
        if guild.id not in self.settings:
            return
        if not self.settings[guild.id]["invite_created"]["enabled"]:
            return
        try:
            channel = await self.modlog_channel(guild, "invite_created")
        except RuntimeError:
            return
        embed_links = (
            channel.permissions_for(guild.me).embed_links
            and self.settings[guild.id]["invite_created"]["embed"]
        )
        invite_attrs = {
            "code": _("Code:"),
            "inviter": _("Inviter:"),
            "channel": _("Channel:"),
            "max_uses": _("Max Uses:"),
        }
        try:
            invite_time = invite.created_at.strftime("%H:%M:%S")
        except AttributeError:
            invite_time = datetime.datetime.utcnow().strftime("%H:%M:%S")
        msg = _("{emoji} `{time}` Invite created ").format(
            emoji=self.settings[guild.id]["invite_created"]["emoji"], time=invite_time,
        )
        embed = discord.Embed(
            title=_("Invite Created"),
            colour=await self.get_event_colour(guild, "invite_created")
        )
        worth_updating = False
        for attr, name in invite_attrs.items():
            before_attr = getattr(invite, attr)
            if before_attr:
                worth_updating = True
                msg += f"{name} {before_attr}\n"
                embed.add_field(name=name, value=str(before_attr))
        if not worth_updating:
            return
        if embed_links:
            await channel.send(embed=embed)
        else:
            await channel.send(escape(msg, mass_mentions=True)) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:49,代码来源:eventmixin.py

示例8: on_invite_delete

# 需要导入模块: import discord [as 别名]
# 或者: from discord import Invite [as 别名]
def on_invite_delete(self, invite: discord.Invite) -> None:
        """
            New in discord.py 1.3
        """
        guild = invite.guild
        if guild.id not in self.settings:
            return
        if not self.settings[guild.id]["invite_deleted"]["enabled"]:
            return
        try:
            channel = await self.modlog_channel(guild, "invite_deleted")
        except RuntimeError:
            return
        embed_links = (
            channel.permissions_for(guild.me).embed_links
            and self.settings[guild.id]["invite_deleted"]["embed"]
        )
        invite_attrs = {
            "code": _("Code: "),
            "inviter": _("Inviter: "),
            "channel": _("Channel: "),
            "max_uses": _("Max Uses: "),
            "uses": _("Used: "),
        }
        try:
            invite_time = invite.created_at.strftime("%H:%M:%S")
        except AttributeError:
            invite_time = datetime.datetime.utcnow().strftime("%H:%M:%S")
        msg = _("{emoji} `{time}` Invite deleted ").format(
            emoji=self.settings[guild.id]["invite_deleted"]["emoji"], time=invite_time,
        )
        embed = discord.Embed(
            title=_("Invite Deleted"),
            colour=await self.get_event_colour(guild, "invite_deleted")
        )
        worth_updating = False
        for attr, name in invite_attrs.items():
            before_attr = getattr(invite, attr)
            if before_attr:
                worth_updating = True
                msg += f"{name} {before_attr}\n"
                embed.add_field(name=name, value=str(before_attr))
        if not worth_updating:
            return
        if embed_links:
            await channel.send(embed=embed)
        else:
            await channel.send(escape(msg, mass_mentions=True)) 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:50,代码来源:eventmixin.py


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