stars.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:LunaBot 作者: miraai 项目源码 文件源码
def moonboard(self, ctx, *, name: str = 'moonboard'):
        """Sets up the starboard for this server.

        This creates a new channel with the specified name
        and makes it into the server's "starboard". If no
        name is passed in then it defaults to "starboard".
        If the channel is deleted then the starboard is
        deleted as well.

        You must have Administrator permissions to use this
        command or the Bot Admin role.
        """

        server = ctx.message.server

        stars = self.stars.get(server.id, {})
        old_starboard = self.bot.get_channel(stars.get('channel'))
        if old_starboard is not None:
            fmt = 'This channel already has a moonboard ({.mention})'
            await self.bot.say(fmt.format(old_starboard))
            return

        # an old channel might have been deleted and thus we should clear all its star data
        stars = {}

        my_permissions = ctx.message.channel.permissions_for(server.me)
        args = [server, name]

        if my_permissions.manage_roles:
            mine = discord.PermissionOverwrite(read_messages=True, send_messages=True)
            everyone = discord.PermissionOverwrite(send_messages=False, embed_links=False)
            args.append((server.me, mine))
            args.append((server.default_role, everyone))

        try:
            channel = await self.bot.create_channel(*args)
        except discord.Forbidden:
            await self.bot.say('**Error!** I do not have permissions to create a channel.')
        except discord.HTTPException:
            await self.bot.say('**Error!** This channel name is bad or an unknown error happened.')
        else:
            stars['channel'] = channel.id
            await self.stars.put(server.id, stars)
            await self.bot.say('**Done!** Moonboard created at ' + channel.mention)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号