Skip to content

Commit

Permalink
add error handling for server DMs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ast3risk-ops committed Jan 9, 2025
1 parent ca114a3 commit 85b8aa6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
36 changes: 21 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,27 @@ async def bookmark_tag(
if modal.children[0].value:
embed.add_field(name="<:mditag:1311505882047189012> Tags", value=f"{modal.children[0].value}", inline=True)
embed.set_thumbnail(url=ezcord.utils.avatar(f"{message.author.id}"))
await ctx.user.send(embed=embed, view=DeleteBookmark())
for i in message.attachments:
path = f"./{i.filename}"
await i.save(path)
await ctx.user.send(file=discord.File(path))
os.remove(path)
if message.stickers:
stickers = []
for i in message.stickers:
format = f'[{i.name}]({i.url})'
stickers.append(format)
await ctx.user.send(' '.join(stickers))
if message.embeds:
for i in message.embeds:
await ctx.user.send(embed=i)
try:
await ctx.user.send(embed=embed, view=DeleteBookmark())
except discord.Forbidden:
await ctx.respond("☹️ I can't DM you! Please enable DMs for this server and try again.", ephemeral=True)
except discord.HTTPException:
await ctx.respond("☹️ I can't DM you! (Unknown HTTP exception, please contact my developer if the issue persists)", ephemeral=True)
else:
for i in message.attachments:
path = f"./{i.filename}"
await i.save(path)
await ctx.user.send(file=discord.File(path))
os.remove(path)
if message.stickers:
stickers = []
for i in message.stickers:
format = f'[{i.name}]({i.url})'
stickers.append(format)
await ctx.user.send(' '.join(stickers))
if message.embeds:
for i in message.embeds:
await ctx.user.send(embed=i)


if __name__ == "__main__":
Expand Down
37 changes: 21 additions & 16 deletions main_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,26 @@ async def bookmark_tag(
if modal.children[0].value:
embed.add_field(name="🔖 Tags", value=f"{modal.children[0].value}", inline=True)
embed.set_thumbnail(url=ezcord.utils.avatar(f"{message.author.id}"))
await ctx.user.send(embed=embed, view=DeleteBookmark())
for i in message.attachments:
path = f"./{i.filename}"
await i.save(path)
await ctx.user.send(file=discord.File(path))
os.remove(path)
if message.stickers:
stickers = []
for i in message.stickers:
format = f'[{i.name}]({i.url})'
stickers.append(format)
await ctx.user.send(' '.join(stickers))
if message.embeds:
for i in message.embeds:
await ctx.user.send(embed=i)

try:
await ctx.user.send(embed=embed, view=DeleteBookmark())
except discord.Forbidden:
await ctx.respond("☹️ I can't DM you! Please enable DMs for this server and try again.", ephemeral=True)
except discord.HTTPException:
await ctx.respond("☹️ I can't DM you! (Unknown HTTP exception, please contact my developer if the issue persists)", ephemeral=True)
else:
for i in message.attachments:
path = f"./{i.filename}"
await i.save(path)
await ctx.user.send(file=discord.File(path))
os.remove(path)
if message.stickers:
stickers = []
for i in message.stickers:
format = f'[{i.name}]({i.url})'
stickers.append(format)
await ctx.user.send(' '.join(stickers))
if message.embeds:
for i in message.embeds:
await ctx.user.send(embed=i)
if __name__ == "__main__":
bot.run(str(os.getenv('TOKEN'))) # run the bot with the token

0 comments on commit 85b8aa6

Please sign in to comment.