I have a command to DM a user anonymously and log the interaction:
@bot.command(name = "dmuser", description = "Send an anonymous DM to a user")
@guild_only()
async def dmuser(ctx, user: discord.Option(discord.Member, "Who to send the DM to?"), msg):
if ctx.author.id in blocked_users_dmuser:
await ctx.respond("Hm, it seems like you don't have permission to run this. Please contact TheMineCommander#5367 or use /support if you believe this is an error.", ephemeral=True)
return
elif user not in ctx.guild.members:
await ctx.respond("This user is not in your guild.",ephemeral=True)
return
else:
dmchannel = await bot.create_dm(user)
uuid = random.choices(string.ascii_lowercase + string.digits, k=20)
uuid = ''.join(uuid)
msg = msg.replace("\\n", "\n")
await dmchannel.send(f"You got an anonymous DM from **{ctx.guild}**!\n--\n```\n{msg}\n```\n--\nIf you would like to report this message, please contact TheMineCommander#5367.\nThe message UUID is `{uuid}`.")
async with aiohttp.ClientSession() as session:
webhook = discord.Webhook.from_url('https://discord.com/api/webhooks/1091580748131217519/URL CUT OUT FOR SECURITY', session=session)
await webhook.send(f"Author: {ctx.author.id}, {ctx.author.name}\nFrom server: {ctx.guild.name}, {ctx.guild.id}\nRecipient: {user},\nUUID: {uuid}\n\n\n```\n{msg}\n```")
await ctx.respond("Sent DM!", ephemeral=True)
However, it DMs three times and logs it three times. Why is this?
I only expected it to run once.
Turns out I had run the bot 3 times