[英]DM on discord.py bot startup
當我的機器人代碼開始運行時,我得到了這段代碼。 但是,我也希望它在代碼開始運行時直接向我發送一條消息,說“機器人在線”。 我該怎么做?
我的代碼:
@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.")
你可以這樣做:
@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.")
其中MY_ID
是您的 discord ID(和 integer 值)。 另請注意,要使其正常工作,您必須允許服務器 DM,並且機器人必須與您位於同一服務器中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.