列表guilds discord.py
这是我的代码:
@client.event
async def on_ready():
print('CONSOLE: We have logged in as {0.user}'.format(client))
async def serverList():
for guild in client.guilds:
print(guild.id)
client.run(token)
I am trying to list the guild/servers the bot is in but this code does not work
This is my code:
@client.event
async def on_ready():
print('CONSOLE: We have logged in as {0.user}'.format(client))
async def serverList():
for guild in client.guilds:
print(guild.id)
client.run(token)
I am trying to list the guild/servers the bot is in but this code does not work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了使您的代码工作要工作,您需要删除行
async def serverlist():
和正确的凹痕,因此循环的与第一个级别相同
print('console ...
代码可能是由于划痕错误而无法运行的 - 您在
async def serverlist()
中都有额外的不必要缩进,或者如果有问题
guild.id
s不会打印,然后发生,因为您使用async def
定义功能,但最终不会在代码中使用它。In order to get your code to work you need to delete the line
async def serverList():
and correct indents so thefor
loop is on the same level with the very firstprint('CONSOLE...
Code does not run probably because of wrong indents - you have an extra unnecessary indent in your
async def serverList()
,or if the problem that
guild.id
s do not get printed then is happening because you define the function withasync def
but you don't end up using it in your code.