From ff6ad8de755221a9168e59de8cda77790c46315f Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Mon, 4 May 2020 17:09:08 +0200 Subject: Handle staff users and DMs in the halloweenify cog The bot doesn't have enough rights to modify staff nicknames, and can't change it when it is invoked through DM neither. --- bot/exts/halloween/halloweenify.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py index 5c433a81..e8ec5ec7 100644 --- a/bot/exts/halloween/halloweenify.py +++ b/bot/exts/halloween/halloweenify.py @@ -4,6 +4,7 @@ from pathlib import Path from random import choice import discord +from discord.errors import Forbidden from discord.ext import commands from discord.ext.commands.cooldowns import BucketType @@ -37,11 +38,25 @@ class Halloweenify(commands.Cog): f"**{ctx.author.display_name}** wasn\'t spooky enough for you? That\'s understandable, " f"{ctx.author.display_name} isn\'t scary at all! " "Let me think of something better. Hmm... I got it!\n\n " - f"Your new nickname will be: \n :ghost: **{nickname}** :jack_o_lantern:" ) embed.set_image(url=image) - await ctx.author.edit(nick=nickname) + try: + if isinstance(ctx.author, discord.Member): + await ctx.author.edit(nick=nickname) + embed.description += f"Your new nickname will be: \n:ghost: **{nickname}** :jack_o_lantern:" + + else: # The command has been invoked in DM + embed.description += ( + f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n" + f"Feel free to change it yourself, or invoke the command again inside the server." + ) + + except Forbidden: # The bot doesn't have enough permission + embed.description += ( + f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n" + f"Although it looks like I can't change it myself, but feel free to change it yourself." + ) await ctx.send(embed=embed) -- cgit v1.2.3 From 3f7a0a298ee469529ba9dac5af2399e28ca1e401 Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Sat, 9 May 2020 16:14:13 +0200 Subject: Update halloweenify error message to make it more readable and restructure the flow --- bot/exts/halloween/halloweenify.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'bot') diff --git a/bot/exts/halloween/halloweenify.py b/bot/exts/halloween/halloweenify.py index e8ec5ec7..a19066cf 100644 --- a/bot/exts/halloween/halloweenify.py +++ b/bot/exts/halloween/halloweenify.py @@ -41,21 +41,21 @@ class Halloweenify(commands.Cog): ) embed.set_image(url=image) - try: - if isinstance(ctx.author, discord.Member): + if isinstance(ctx.author, discord.Member): + try: await ctx.author.edit(nick=nickname) embed.description += f"Your new nickname will be: \n:ghost: **{nickname}** :jack_o_lantern:" - else: # The command has been invoked in DM + except Forbidden: # The bot doesn't have enough permission embed.description += ( f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n" - f"Feel free to change it yourself, or invoke the command again inside the server." + f"It looks like I cannot change your name, but feel free to change it yourself." ) - except Forbidden: # The bot doesn't have enough permission + else: # The command has been invoked in DM embed.description += ( f"Your new nickname should be: \n :ghost: **{nickname}** :jack_o_lantern: \n\n" - f"Although it looks like I can't change it myself, but feel free to change it yourself." + f"Feel free to change it yourself, or invoke the command again inside the server." ) await ctx.send(embed=embed) -- cgit v1.2.3