如何在discord.py中找到发送起始消息的默认通道?



我想让我的机器人找到第一个通道,这是一个文本通道,他有权限发送消息。问题是我不知道如何检查每个通道的权限。

# 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 

你的可能性很小

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

@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

最新更新