[V3 Core] Fix error on [p]set command when used in DM (#1748)

* issue #1741 fix

* requested changes
This commit is contained in:
Michael H 2018-06-01 19:26:12 -04:00 committed by Tobotimus
parent 34bd5ead15
commit 9f0e752318

View File

@ -515,28 +515,25 @@ class Core:
async def _set(self, ctx):
"""Changes Red's settings"""
if ctx.invoked_subcommand is None:
admin_role_id = await ctx.bot.db.guild(ctx.guild).admin_role()
admin_role = discord.utils.get(ctx.guild.roles, id=admin_role_id)
mod_role_id = await ctx.bot.db.guild(ctx.guild).mod_role()
mod_role = discord.utils.get(ctx.guild.roles, id=mod_role_id)
prefixes = await ctx.bot.db.guild(ctx.guild).prefix()
if ctx.guild:
admin_role_id = await ctx.bot.db.guild(ctx.guild).admin_role()
admin_role = discord.utils.get(ctx.guild.roles, id=admin_role_id) or "Not set"
mod_role_id = await ctx.bot.db.guild(ctx.guild).mod_role()
mod_role = discord.utils.get(ctx.guild.roles, id=mod_role_id) or "Not set"
prefixes = await ctx.bot.db.guild(ctx.guild).prefix()
guild_settings = f"Admin role: {admin_role}\nMod role: {mod_role}\n"
else:
guild_settings = ""
if not prefixes:
prefixes = await ctx.bot.db.prefix()
locale = await ctx.bot.db.locale()
prefix_string = " ".join(prefixes)
settings = (
"{} Settings:\n\n"
"Prefixes: {}\n"
"Admin role: {}\n"
"Mod role: {}\n"
"Locale: {}"
"".format(
ctx.bot.user.name,
" ".join(prefixes),
admin_role.name if admin_role else "Not set",
mod_role.name if mod_role else "Not set",
locale,
)
f"{ctx.bot.user.name} Settings:\n\n"
f"Prefixes: {prefix_string}\n"
f"{guild_settings}"
f"Locale: {locale}"
)
await ctx.send(box(settings))
await ctx.send_help()