如何在discord.py中定义行会?

时间:2019-03-19 18:55:05

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

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

我如何定义公会?

1 个答案:

答案 0 :(得分:0)

member.guild重写或member.server异步

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

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