0

I am trying to send a message through the python console. Right now, I have everything working when I set it as a bot command (When I do the command !dm, I get prompted in the python console The user Id and message I want to DM. This all works. However, what I am trying to do is for the program to prompt me as soon as it is started.

My current code:

@bot.command(name='dm')
async def messageinput(ctx):
    member = input('Enter Member ID: ')
    message = input('Enter Message: ')
    print(member)
    print(message)
    user = bot.get_user(int(member))
    await user.send(message)

@bot.event
async def on_ready():
    #await verifyloop()
    print(Fore.CYAN + '|------------------------------------------|')
    print(Fore.CYAN + '|--------------Bot is online!--------------|')
    print(Fore.CYAN + '|------------------------------------------|')
    
    #await messageinput()

How do I do this?

ENORMOUZ
  • 25
  • 2
  • 11

2 Answers2

1

To get a discord member using their ID in the on_ready() function, you do this:

await client.fetch_user(USER_ID)

Where USER_ID is the user's ID (an integer value).


So, your event would look like this:

@bot.event
async def on_ready():
    print(Fore.CYAN + '|------------------------------------------|')
    print(Fore.CYAN + '|--------------Bot is online!--------------|')
    print(Fore.CYAN + '|------------------------------------------|')

    member = int(input('Enter Member ID: '))
    message = input('Enter Message: ')

    user = await bot.fetch_user(member)
    await user.send(message)
Sujit
  • 1,653
  • 2
  • 9
  • 25
0

Don't use print, print sends the message to the console, use ctx.send instead, for more information, check out the discord.py documentation.

An example:

ctx.send("Sending this to the designated channel on Discord")
  • Like I said, I already have it working as a bot command. However, I want it to prompt me when I start the program (So I do not have to open discord. – ENORMOUZ Jan 05 '21 at 04:14