-2

我希望我的机器人找到第一个频道,这是一个文本频道,并且他有权在其中发送消息。问题是我不知道如何检查每个频道的权限。

# When the bot is ready
@client.event
async def on_ready():

    # Ready message
    print("Bot is ready.")

    # Getting the default channel
    default_channel = checkChannels()


# Getting the default channel
@bot_has_permissions(send_messages=True)
def checkChannels():
    for guild in client.guilds:
            for channel in guild.channels:
                if str(channel.type) == "text":
                        return channel 
4

1 回答 1

0

你的可能性很小。

如果你想找到system_channel(Discord 的欢迎信息在这里发送):

@client.event
async def on_ready():
    for guild in client.guilds:
        channel = guild.system_channel #getting system channel
        if channel.permissions_for(guild.me).send_messages: #making sure you have permissions
            await channel.send("I'm online!")

这样,您将找到您有权访问的第一个频道

@client.event
async def on_ready():
    for guild in client.guilds:
        for channel in guild.text_channels: #getting only text channels
            if channel.permissions_for(guild.me).send_messages: #checking if you have permissions
                await channel.send("I'm online!")
                break #breaking so you won't send messages to multiple channels
于 2021-10-16T11:20:42.243 回答