Python 3.x Python Discord Bot,需要服务器ID

Python 3.x Python Discord Bot,需要服务器ID,python-3.x,discord.py,discord.py-rewrite,Python 3.x,Discord.py,Discord.py Rewrite,我正在用python创建一个discord bot,为了将数据保存在我的计算机上,我在文本文件中使用了一个字典,但是如果我想要像config这样的多服务器支持,我需要知道服务器的id。我发现唯一可以工作的是discord.server.id,但它返回。我想知道在python中是否还有其他方法可以做到这一点?我的确切代码是: @bot.command(pass_context=True) async def info(ctx): await bot.say("ID: {}".format(

我正在用python创建一个discord bot,为了将数据保存在我的计算机上,我在文本文件中使用了一个字典,但是如果我想要像config这样的多服务器支持,我需要知道服务器的id。我发现唯一可以工作的是
discord.server.id
,但它返回
。我想知道在python中是否还有其他方法可以做到这一点?我的确切代码是:

@bot.command(pass_context=True)
async def info(ctx):
    await bot.say("ID: {}".format(discord.Server.id))
返回

ID: <member 'id' of 'Server' objects>
ID:
当我运行c*info(c*是我的机器人的前缀)时。我不知道这个错误的原因或者我做错了什么,所以请帮助我


谢谢

您可以从
ctx
获取
服务器
类的实例。该对象将具有有意义的
id
属性

@bot.command(pass_context=True)
async def info(ctx):
    await bot.say("ID: {}".format(ctx.message.server.id))
因为,这将是

@bot.command()
async def info(ctx):
    await ctx.send("ID: {}".format(ctx.guild.id))