我正在用 python 创建一个不和谐的机器人,为了将数据保存在我的计算机上,我在文本文件中使用字典,但如果我想要多服务器支持诸如配置之类的东西,我需要知道服务器的 ID。我发现唯一可行的是discord.Server.id
但它返回<member 'id' of 'Server' objects>
。我想知道在 python 中是否还有其他方法可以做到这一点?我的确切代码是这样的:
@bot.command(pass_context=True)
async def info(ctx):
await bot.say("ID: {}".format(discord.Server.id))
返回
ID: <member 'id' of 'Server' objects>
当我运行 c*info (c* 是我的机器人的前缀)时。我不知道这个错误的原因或我做错了什么,所以请帮助!
Thanks
您可以获得一个实例Server
类来自命令调用上下文 https://discordpy.readthedocs.io/en/rewrite/ext/commands/commands.html#invocation-context ctx
。该对象将具有有意义的id
属性。
@bot.command(pass_context=True)
async def info(ctx):
await bot.say("ID: {}".format(ctx.message.server.id))
For 不和谐.py重写 /questions/tagged/discord.py-rewrite,这将是
@bot.command()
async def info(ctx):
await ctx.send("ID: {}".format(ctx.guild.id))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)