【问题标题】:How to make join/leave messages in discord.py如何在 discord.py 中加入/离开消息
【发布时间】:2019-05-01 01:56:58
【问题描述】:
@bot.event
async def on_member_join(member):
    fmt = "{} has joined"
    await bot.send_message(member, fmt.format(member, member.server))

@bot.event
async def on_member_remove(member):
    fmt = '{} has left'
    await bot.send_message(member, fmt.format(member, member.server))

这是我的代码,我想在不添加的情况下加入并留言

channel = member.server.get_channel("CHANNEL_ID")

此代码使所有使用此机器人的服务器都可以使用加入/离开消息。 如果我输入此代码,我可以只为特定服务器使用加入和留言。

【问题讨论】:

  • 您想如何确定将消息发送到哪个频道?

标签: python bots discord discord.py


【解决方案1】:

discord 频道 ID 专用于一个频道,您不能在多个频道/服务器上拥有相同的 ID。
您可以尝试为欢迎频道使用单一名称:

channel = discord.utils.get(ctx.guild.channels, id=modlog)

或者使用数据库,每个服务器都可以为欢迎频道保存自己的频道 ID,您可以这样使用:

channel = discord.utils.get(ctx.guild.channels, id=modlog)

【讨论】:

    猜你喜欢
    • 2021-05-16
    • 2021-08-23
    • 2020-11-01
    • 1970-01-01
    • 2021-02-13
    • 2020-03-17
    • 1970-01-01
    • 2021-12-11
    • 2023-04-02
    相关资源
    最近更新 更多