Reputation: 67
I've got this code for when my bot code begins to be run. However, I'd also like it to DM me directly with a message saying "The bot is online" whenever the code begins running. How to I do that?
My Code:
@bot.event
async def on_ready():
activity = discord.Game(name="DM's being sent", type=3)
await bot.change_presence(
activity = discord.Activity(
type = discord.ActivityType.watching,
name = "Pokemon Go Discord Server!"
)
)
channel = bot.get_channel(MY_CHANNEL_ID)
await channel.send("Bot ready.")
print("Ready.")
Upvotes: 0
Views: 360
Reputation: 1792
You can do it this way:
@bot.event
async def on_ready():
await bot.change_presence(
activity = discord.Activity(
type = discord.ActivityType.watching,
name = "Pokemon Go Discord Server!"
)
)
member = await bot.fetch_user(MY_ID)
await member.send("The bot is online")
print("Ready.")
Where MY_ID
is your discord ID (and integer value). Also note that for this to work you'll have to allow server DMs and the bot has to be in the same server as you are.
Upvotes: 1