2 回答

TA貢獻1829條經驗 獲得超7個贊
由于沒有“邀請”機器人,因此當添加機器人時會有一個審核日志事件。這使您可以遍歷匹配特定條件的日志。
如果您的機器人可以訪問審核日志,您可以搜索bot_add事件:
@client.event
async def on_guild_join(guild):
bot_entry = await guild.audit_logs(action=discord.AuditLogAction.bot_add).flatten()
await bot_entry[0].user.send("Hello! Thanks for inviting me!")
如果您希望根據您自己的 ID 仔細檢查機器人的 ID:
@client.event
async def on_guild_join(guild):
def check(event):
return event.target.id == client.user.id
bot_entry = await guild.audit_logs(action=discord.AuditLogAction.bot_add).find(check)
await bot_entry.user.send("Hello! Thanks for inviting me!")

TA貢獻1884條經驗 獲得超4個贊
從這篇文章
使用discord.py 2.0,您可以獲得BotIntegration
服務器的信息以及邀請機器人的用戶信息。
例子
from discord.ext import commands
bot = commands.Bot()
@bot.event
async def on_guild_join(guild):
# get all server integrations
integrations = await guild.integrations()
for integration in integrations:
if isinstance(integration, discord.BotIntegration):
if integration.application.user.name == bot.user.name:
bot_inviter = integration.user# returns a discord.User object
# send message to the inviter to say thank you
await bot_inviter.send("Thank you for inviting my bot!!")
break
注意: guild.integrations()
需要Manage Server
( manage_guild
) 權限。
添加回答
舉報