亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python discord.py 在加入公會時向邀請者發送 DM

python discord.py 在加入公會時向邀請者發送 DM

墨色風雨 2022-12-27 17:15:13
我目前有以下on_guild_join代碼:@client.eventasync def on_guild_join(guild):    embed = discord.Embed(title='Eric Bot', color=0xaa0000)    embed.add_field(name="What's up everyone? I am **Eric Bot**.", value='\nTry typing `/help` to get started.', inline=False)    embed.set_footer(text='Thanks for adding Eric Bot to your server!')    await guild.system_channel.send(embed=embed)    print(f'{c.bgreen}>>> {c.bdarkred}[GUILD JOINED] {c.black}ID: {guild.id} Name: {guild.name}{c.bgreen} <<<\n{c.darkwhite}Total Guilds: {len(client.guilds)}{c.end}')(忽略這些c.color東西,這是我在控制臺上的格式)每當有人將機器人添加到公會時,它都會向系統頻道發送一個帶有一些信息的嵌入。我希望它向邀請機器人(使用 oauth 授權鏈接的帳戶)發送相同消息的人發送 DM。問題是該on_guild_join事件僅采用 1 個參數,guild它不會為您提供有關使用授權鏈接將機器人添加到公會的人的任何信息。有沒有辦法做到這一點?我是否必須使用“作弊”方法,例如擁有一個記錄使用邀請的帳戶的自定義網站?
查看完整描述

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!")


查看完整回答
反對 回復 2022-12-27
?
慕村9548890

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 Servermanage_guild) 權限。



查看完整回答
反對 回復 2022-12-27
  • 2 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號