Discord Get Guild未返回对象

Discord Get Guild未返回对象,discord,discord.py,Discord,Discord.py,我试图通过服务器ID获取服务器对象。我知道服务器ID是正确的,但由于某些原因,函数没有返回任何值 client = discord.Client() TOKEN = "mytoken" client.login(TOKEN) server_id=846557514476945408 #this is my own server id guild=client.get_guild(server_id) 我已检查并确保我的客户端连接已打开 不确定这是否重要,但我看到了这些警

我试图通过服务器ID获取服务器对象。我知道服务器ID是正确的,但由于某些原因,函数没有返回任何值

client = discord.Client()
TOKEN = "mytoken"
client.login(TOKEN)

server_id=846557514476945408 #this is my own server id
guild=client.get_guild(server_id)

我已检查并确保我的客户端连接已打开

不确定这是否重要,但我看到了这些警告

<input>:1: RuntimeWarning: coroutine 'Client.connect' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
:1:运行时警告:从未等待协同路由“Client.connect”
RuntimeWarning:启用tracemalloc以获取对象分配回溯

在客户端准备就绪之前,
服务器id
帮会
变量会运行,因此您总是会收到
。由于
client.login()
是一个协同程序,因此代码似乎没有正确设置。下面我删除了
client.login()
,改为使用
client.run()
,并使用discord.py中的最小bot示例来利用包含的on_ready事件


我只是快速看了一下,但我注意到您使用了
server\u ID
作为变量名,但随后在get\u guild中使用了
server\u ID
。变量区分大小写。是的,你是对的,我更改了它,但它仍然没有返回任何内容:(你是想通过自己的帐户还是机器人登录?在
client.login(令牌)上)
我通过bot登录,我从bot获得了令牌,有没有办法不用bot就用我的帐户登录?我真的不需要bot在这种情况下,我相信使用用户令牌作为bot是不符合TOS的。我只是看到人们使用
client.run()
比使用
client.login()更频繁
import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    server_id = 846557514476945408 #this is my own server id
    guild = client.get_guild(server_id)

client.run("TOKEN")