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)
评论列表
文章目录