【问题标题】:How to define guild in discord.py?如何在 discord.py 中定义公会?
【发布时间】:2019-03-19 18:55:05
【问题描述】:
async def find_channel(guild):
for c in guild.text_channels:
    if not c.permissions_for(guild.me).send_messages:
        continue
    return c

@bot.event
async def on_server_join(member):
channel = await find_channel(guild)
await channel.send('blah')

这是我的代码,当我启动机器人并加入频道时,会出现此错误:

line 48, in on_server_join
channel = await find_channel(guild)
NameError: name 'guild' is not defined

如何定义公会?

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    member.guild 重写或 member.server 异步

    discord.Member 有一个允许检索公会的特定字段。

    假设您使用的是重写版本,而不是 channel = await find_channel(guild),只需执行 channel = await find_channel(member.guild)

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2019-08-15
      • 2021-07-19
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 2020-09-24
      • 2021-03-14
      • 2021-12-04
      相关资源
      最近更新 更多