Skip to main content
 首页 » 编程设计

python-3.x之消息对象没有属性 'server'

2024年12月31日18qq78292959

使用以下代码行:

@bot.command() 
async def report(ctx): 
  author = ctx.message.author 
  server = ctx.message.server 
  wait ctx.send("Author: " + str(author) + "\nServer: " + str(server)) 

我收到错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Message' object has no attribute 'server' 

导入库不是问题,因为我可以将行更改为 ctx.message.channel并获取 channel 名称。 author收藏也不错。但是 server才不是。我也试过使用 Guild根据一些没有运气的建议。

请您参考如下方法:

discord.py 重写版本不使用 Server消除公会和语音服务器之间的歧义,并与 Discord 的内部代码保持一致。

而不是做

discord.Server 
message.server 
etc.server 


discord.Guild 
message.guild 
etc.guild