Home > OS >  Is there a method to impersonate another bot to send an embed in discord.py
Is there a method to impersonate another bot to send an embed in discord.py

Time:08-31

I am currently working on a game bot, however I have encountered a tricky situation. I want to be able to make my bot look like a different bot entirely, by temporarily changing the name and avatar to send an embed. I have tried:

with open("shadytrader.png", "rb") as img:
    await client.user.edit(
        username="The shady trader",
        avatar=img.read()
    )

Which works fine until I want to change the name back, at which point discord either bugs out and shows none of the changes, or raises an error telling me that I am changing the bots name and avatar too fast. I also tried embed.set_author("Shady trader", "icon_url", which just makes the embed look worse and does not change the image or name of the bot when sending the message.

Is there a way to temporarily and reliably change the name and icon of the bot to send an embed?

CodePudding user response:

Discord only lets you change your name twice every hour and the changes may take up to an hour to be shown to everyone, you don't have any influence on that. Also, when you change the name, the messages you sent before the change will update to the new name.

While this method might be the most legitimate looking to random people seeing it, another method you could try (what i personally would recommend you) is to send the message using a webhook. I put together this solution that temporarily creates a webhook that looks like another user when used. Simply replace ORIGINAL_USER_ID with the User ID of the account you are trying to imitate.

# The original user is fetched from its ID
# Change 'ORIGINAL_USER_ID' to the ID of the user you are trying to imitate
original = await client.fetch_user('ORIGINAL_USER_ID')

# Downloading the avatar of the user you are trying to imitate
import requests
req = requests.get(url=original.avatar.url)
avatar = req.content

# Creating the webhook looking like the user
webhook = await ctx.channel.create_webhook(name=original.name, avatar=avatar)

# Sending the message. Set this to anything you want.
await webhook.send("This message looks like it was sent by someone else.")

# Here you can do whatever you want with the webhook...

# Deleting the webhook when everything is done
await webhook.delete()

This code also automatically downloads the avatar and the username, if you want to use your own method feel to put in your code, this is not related to the webhooks.

  • Related