列表guilds discord.py

发布于 2025-02-13 17:31:47 字数 380 浏览 0 评论 0原文

这是我的代码:

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2025-02-20 17:31:47

为了使您的代码工作要工作,您需要删除行async def serverlist():和正确的凹痕,因此循环的与第一个级别相同print('console ...

@client.event
async def on_ready():
    print('CONSOLE: We have logged in as {0.user}'.format(client))

    for guild in client.guilds:
        print(guild.id)

client.run(token)

代码可能是由于划痕错误而无法运行的 - 您在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 the for loop is on the same level with the very first print('CONSOLE...

@client.event
async def on_ready():
    print('CONSOLE: We have logged in as {0.user}'.format(client))

    for guild in client.guilds:
        print(guild.id)

client.run(token)

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.ids do not get printed then is happening because you define the function with async def but you don't end up using it in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文