欢迎信息发送到我的服务器?

时间:2021-07-29 17:12:10

标签: discord discord.py

我在代码中指定了频道 ID。当新成员加入我的服务器时,消息会发送到我想要的频道,但是当我服务器的成员加入我的机器人所在的另一台服务器时,欢迎消息会发送到我的服务器,尽管该成员已经在它上面,刚刚加入了另一台服务器。我的问题是,当成员加入另一台服务器时,如何修复机器人不向我的服务器发送欢迎消息?

我的第二个问题是,我该如何设置,例如,其他服务器的管理员可以选择将欢迎消息发送到他们服务器的位置?

@client.event
async def on_member_join(member):
    embed = discord.Embed(color=0x6c5ce7)
    embed.set_thumbnail(url=member.avatar_url)
    embed.add_field(name=f"Welcome, {member.name}#{member.discriminator}!\n", value=f":white_small_square: Check the <#848929002281631744> channel and read the rules!\n"
                                                                                                f":white_small_square: Then look in the <#848929105109057567> channel and follow the instructions!\n\n"
                                                                                                f"Have fun on our Server!", inline=True)
    embed.set_footer(text=f"New Member: {member.name}#{member.discriminator}", icon_url=member.avatar_url)
    await client.get_channel(865655108230447175).send(embed=embed)

1 个答案:

答案 0 :(得分:0)

您可以这样做的一种方法是检查成员加入的公会是否是您的公会。最好和最准确的方法是通过 id。

@client.event
async def on_member_join(member):
    # check if the guild the member is joining is equal to your guild's id 
    if member.guild.id != YOUR GUILD ID:
        return
    # if it's the same guild id, it continues
    embed = discord.Embed(color=0x6c5ce7)
    # etc, other code

如果你想在你自己的多个服务器上使用它,你可以考虑使用一个 json,它可以存储公会 id 和频道 id,并使用与上面代码中看到的类似的概念。

>