Skip to content

Commit 011c76d

Browse files
committed
[captcha] fix if no dm was created before captcha
also fix possible issue with deleted channels from config
1 parent f788a54 commit 011c76d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

captcha/api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ def __init__(self, bot: Red, member: discord.Member, data: dict):
2828
self.guild: discord.Guild = member.guild
2929
self.config: dict = data # Will contain the config of the guild.
3030

31+
self.channel: Union[discord.TextChannel, discord.DMChannel]
3132
if not self.config["channel"]:
3233
raise MissingRequiredValueError("Missing channel for verification.")
33-
self.channel: Union[discord.TextChannel, discord.DMChannel] = (
34-
bot.get_channel(self.config["channel"])
35-
if self.config.get("channel") != "dm"
36-
else self.member.dm_channel
37-
)
34+
if self.config.get("channel") == "dm":
35+
if not self.member.dm_channel:
36+
self.channel = await self.member.create_dm()
37+
else:
38+
self.channel = self.member.dm_channel()
39+
else:
40+
self.channel = bot.get_channel(self.config["channel"])
41+
if not self.channel:
42+
raise MissingRequiredValueError("Missing channel for verification.")
3843

3944
self.type: str = self.config["type"]
4045

captcha/informations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = ["Predeactor", "Kreusada", "Fixator10"]
2-
__version__ = "1.0.3"
2+
__version__ = "1.0.4"
33

44
__patchnote__ = (
55
"Hello, this cog is (once again) moving of repository. It'll be now hosted by Fixator10 at \n"

0 commit comments

Comments
 (0)