Python discord 模块,Invite() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用discord.Invite()

项目:Shallus-Bot    作者:cgropp    | 项目源码 | 文件源码
def join(self, invite_url: discord.Invite=None):
        """Joins new server"""
        if hasattr(self.bot.user, 'bot') and self.bot.user.bot is True:
            # Check to ensure they're using updated discord.py
            msg = ("I have a **BOT** tag, so I must be invited with an OAuth2"
                   " link:\nFor more information: "
                   "https://twentysix26.github.io/"
                   "Red-Docs/red_guide_bot_accounts/#bot-invites")
            await self.bot.say(msg)
            if hasattr(self.bot, 'oauth_url'):
                await self.bot.whisper("Here's my OAUTH2 link:\n{}".format(
                    self.bot.oauth_url))
            return

        if invite_url is None:
            await self.bot.say("I need a Discord Invite link for the "
                               "server you want me to join.")
            return

        try:
            await self.bot.accept_invite(invite_url)
            await self.bot.say("Server joined.")
            log.debug("We just joined {}".format(invite_url))
        except discord.NotFound:
            await self.bot.say("The invite was invalid or expired.")
        except discord.HTTPException:
            await self.bot.say("I wasn't able to accept the invite."
                               " Try again.")
项目:dogbot    作者:slice    | 项目源码 | 文件源码
def invite_info(self, ctx, invite: discord.Invite):
        """Shows information about an invite."""
        embed = discord.Embed(title=f'Invite for {invite.guild.name} (`{invite.guild.id}`)')
        embed.add_field(name='Channel', value=f'{invite.channel.name} (`{invite.channel.id}`)', inline=False)
        if invite.inviter:
            embed.add_field(name='Inviter', value=describe(invite.inviter, mention=True), inline=False)
        await ctx.send(embed=embed)
项目:KeekoBot    作者:DavidNeon    | 项目源码 | 文件源码
def join(self, invite_url: discord.Invite=None):
        """Joins new server"""
        if hasattr(self.bot.user, 'bot') and self.bot.user.bot is True:
            # Check to ensure they're using updated discord.py
            msg = ("I have a **BOT** tag, so I must be invited with an OAuth2"
                   " link:\nFor more information: "
                   "---"
                   "---")
            await self.bot.say(msg)
            if hasattr(self.bot, 'oauth_url'):
                await self.bot.whisper("Here's my OAUTH2 link:\n{}".format(
                    self.bot.oauth_url))
            return

        if invite_url is None:
            await self.bot.say("I need a Discord Invite link for the "
                               "server you want me to join.")
            return

        try:
            await self.bot.accept_invite(invite_url)
            await self.bot.say("Server joined.")
            log.debug("We just joined {}".format(invite_url))
        except discord.NotFound:
            await self.bot.say("The invite was invalid or expired.")
        except discord.HTTPException:
            await self.bot.say("I wasn't able to accept the invite."
                               " Try again.")