newsannouncer.py 文件源码

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

项目:palmtree5-cogs 作者: palmtree5 项目源码 文件源码
def joinnews(self, ctx):
        """Joins the news role for the current channel"""
        server = ctx.message.server
        channel = ctx.message.channel
        if server.id not in self.settings or\
                channel.id not in self.settings[server.id]:
            await self.bot.say("No news role available here!")
            return
        author = ctx.message.author
        if author.id in self.settings[server.id][channel.id]["joined"]:
            await self.bot.say("You already have the role for this channel!")
            return
        role_id = self.settings[server.id][channel.id]["role_id"]
        role_to_add = [r for r in server.roles if r.id == role_id][0]
        try:
            await self.bot.add_roles(author, role_to_add)
        except discord.Forbidden:
            await self.bot.say("I don't have permissions to add roles here!")
            return
        except discord.HTTPException:
            await self.bot.say("Something went wrong while doing that.")
            return
        await self.bot.say("Added that role successfully")
        self.settings[server.id][channel.id]["joined"].append(author.id)
        dataIO.save_json("data/newsannouncer/settings.json", self.settings)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号