【发布时间】:2019-03-02 23:55:55
【问题描述】:
我希望我的 Bot 从该服务器中的所有 6 个通道发布 pin,但是,我的 bot 仅从调用命令的当前通道获取 pin。我想知道是否有办法解决这个问题。不和谐版本 1.0.0A
我现在的代码是:
if "seepins()" == message.content.lower():
# retrieve and post all pins again
allPins = await message.channel.pins()
for i in allPins:
# Check if pin is text or a link
mat = i.attachments
if len(mat)==0:
await message.channel.send(i.content)
else:
await message.channel.send(mat[0].url)
以下代码从存在此机器人的所有服务器中检索用户详细信息。我想知道是否应该在第一个代码 sn-p 中使用公会而不是频道?结果这给了我一个错误。
if "member_status()" == message.content.lower():
online = 0
idle = 0
offline = 0
print(f"Testing the API with guild.owner: {guild}")
for i in guild.members:
if str(i.status) == "online":
online +=1
elif str(i.status) == "offline":
offline +=1
else:
idle +=1
await message.channel.send(f"```py\ntotal: {guild.member_count} \nonline: {online} \nidle: {idle} \noffline: {offline}```")
【问题讨论】:
-
我之前没有使用过
1.0.0a,但查看文档似乎guild确实有一个channels可迭代的,它可以满足您的需求(参见here )。您可以尝试查看它是否适用于message.guild.channels,然后在循环中的每个通道上调用pins()。不过要小心,因为channels似乎还包括各种渠道,例如语音渠道而不仅仅是文本渠道,因此您可能还需要为TextChannel添加类型检查。 -
感谢 Xay 成功了 :)
标签: python discord.py