I'm trying to get a user's ID via a message ID; the ID of the user I want to send a DM to is in the embed's footer. I'm using this code for it:
msg = await ctx.channel.fetch_message(id)
id2 = int(msg.embeds[0].footer.text)
print(type(id2))
await ctx.send(id2, hidden=True)
# Everything works fine ^
# Everything breaks below
user = client.get_user(id2)
print(type(user))
await ctx.send(user, hidden=True)
await user.send("IT WORKED!!!")
I added some debugging code and it appears to break when it tries to convert it to a user in user = client.get_user(id2)
. It converts it into nothing; I saw that with the type()
function, and in the error:
An exception has occurred while executing command `answer`:
Traceback (most recent call last):
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/client.py", line 1185, in invoke_command
await func.invoke(ctx, **args)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/model.py", line 209, in invoke
return await self.func(*args, **kwargs)
File "/Users/dante_nl/Library/Mobile Documents/com~apple~CloudDocs/Ask/bot.py", line 105, in _answer
await ctx.send(user, hidden=True)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord_slash/context.py", line 239, in send
resp = await self._http.post_followup(base, self._token, files=files)
File "/Users/dante_nl/Library/Python/3.8/lib/python/site-packages/discord/http.py", line 254, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
I'm not sure why it does this, it got the ID from the embed's footer, converted it to a number, but it can't convert it to a user and send a DM to that user.
Thanks in advance!
Note: I'm using slash commands, not sure if that makes any difference.
You can use:
await client.fetch_user(id2)
If this does not work, then maybe id2 is not a valid user id.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments