stars.py 文件源码

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

项目:jose 作者: lnmds 项目源码 文件源码
def starboard(self, ctx, channel_name: str):
        """Create a starboard channel.

        If the name specifies a NSFW channel, the starboard gets marked as NSFW.

        NSFW starboards allow messages from NSFW channels to be starred without any censoring.
        If your starboard gets marked as a SFW starboard, messages from NSFW channels get completly ignored.
        """

        guild = ctx.guild
        config = await self.get_starconfig(guild.id)
        if config is not None:
            await ctx.send("You already have a starboard. If you want"
                           " to detach josé from it, use the "
                           "`stardetach` command")
            return

        po = discord.PermissionOverwrite
        overwrites = {
                guild.default_role: po(read_messages=True, send_messages=False),
                guild.me: po(read_messages=True, send_messages=True),
        }

        try:
            starboard_chan = await guild.create_text_channel(
                channel_name,
                overwrites=overwrites,
                reason='Created starboard channel')

        except discord.Forbidden:
            return await ctx.send('No permissions to make a channel.')
        except discord.HTTPException as err:
            log.exception('Got HTTP error from starboard create')
            return await ctx.send(f'**SHIT!!!!**:  {err!r}')

        log.info(f'[starboard] Init starboard @ {guild.name}[{guild.id}]')

        # create config here
        config = empty_starconfig(guild)
        config['starboard_id'] = starboard_chan.id

        res = await self.starconfig_coll.insert_one(config)
        if not res.acknowledged:
            raise self.SayException('Failed to create starboard config (no ack)')

        await ctx.send('All done, I guess!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号