How Can I Get My Bot To DM A Specific User ID Without A Command Given?
When someone DM's my bot, I have it print to the console who messaged, what the message was, and the time the message was sent. I would like the bot to then DM me to either notify me someone messaged it, and/or who and what and when.
I've seen many issues about this with different solutions. A lot of them were outdated therefore do not work with my code. I use Python 3.7 on Spyder.
I can get the bot to DM a user on bot command but cannot get it to DM a specific user ID which would be mine.
Here's the code that prints DM messages received to the console. Again, no issues with this part. Just need this info private messaged to me.
if isinstance(message.channel, discord.DMChannel):
print("******************************")
print("DM Recieved by: " + message.author.name)
print("Time:", str(datetime.datetime.now()))
print("Message: " + message.content)
print("******************************")
Updated Code:
if client.user.mentioned_in(message) and message.mention_everyone is False:
await message.delete()
channel = message.channel
await channel.trigger_typing()
await channel.send("{0.mention} Please don't tag me.".format(message.author))
print("**************************************************")
print("Mentioned By: " + message.author.name)
print("Time:", str(datetime.datetime.now()))
print("Message: " + message.clean_content)
print("Channel: " + str(message.channel))
print("**************************************************\n")
#DM me when bot get's mentioned.
client.get_user(305508822485827584)
await user.send("Test")
Answer
It seems to me that you're using the old async version of discord.py - I highly recommend moving to the newer rewrite branch as support for the async version has now ceased.
client.get_user(ID)
is a rewrite method and doesn't exist in the async version of discord.py. You can use client.get_user_info(ID)
in this case.
Hope this helps - happy coding!
EDIT: Here's the code you need to use:
user = client.get_user(305508822485827584)
await user.send("Test")
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module