简体   繁体   中英

How do I send dms to a specific person.Discord.py

When my bot comes online I want it to dm me but it wont work. Heres the code.

@client.event
async def on_ready():
    user = client.get_user(id)
    await user.send('bot online')

It says nonetype has no attribute send

@client.event
async def on_ready():
    channel = await member.create_dm()
    await channel.send("Bot is Online")

You have to make a dm through a channel not through a user

You can use get_member command to do this. If you want the bot to DM you specifically, you need to know your user ID, then inser it to a variable. Here is how you can define a simple command to DM someone ( for example you ) on bot startup:

@client.event
async def on_ready():
    yourID = # Enter your ID here...
    discordUser = client.get_user(yourID)

    await discordUser.send('Bot online.')

Just in case you're not sure about how to get your ID, you can check out how to get an ID .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM