discord.py edit_server函数示例

discord.py edit_server函数示例

问题描述:

之前我尝试使用函数edit_server,如discord.py文档所列:http://discordpy.readthedocs.io/en/latest/api.html?highlight=ownership,并且无法弄清楚如何使用它。我想用它来创建一个命令将所有权转让给其他用户。我的代码:discord.py edit_server函数示例

elif message.content.startswith('!ownership): 
    await client.edit_server(server='317161621233467392', owner='323512053862236161')` 

错误:

Traceback (most recent call last): 
    File "C:\Users\parke\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event 
    yield from getattr(self, event)(*args, **kwargs) 
    File ".\start_bot.py", line 33, in on_message 
    await client.edit_server(server='317161621233467392', owner='323512053862236161') 
    File "C:\Users\parke\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 2337, in edit_server 
    icon = server.icon 
AttributeError: 'str' object has no attribute 'icon'` 

可能有人可能告诉我它正确的使用为例,谢谢!

这里是我的所有代码(减去我的令牌):https://pastebin.com/yXPCjUbP

+2

您发布的Python代码是(1)无效和(2)无关。 – DyZ

+0

@DYZ回溯应该属于代码块而不是引号。 https://meta.stackexchange.com/questions/32264/posting-a-stack-trace,因为它有很好的标记,它看起来很整齐。而且,发布的代码OP确实无效,我同意这一点。但实际上它是相关的,因为这是“假设”要完成的,只是不完整。 (我只是因为(1)而提高了你的评论) – abccd

+0

@abccd好的,对不起,我现在就编辑它。 – ParkerSTP

由于文档所述,serverowner需要一个discord.Serverdiscord.Member对象,你不仅可以通过其ID的str表示。

edit_server(server, **fields)This function is a coroutine.

Edits a Server.

You must have the proper permissions to edit the server.

The Server object is not directly modified afterwards until the corresponding WebSocket event is received.

Parameters:

server (Server) – The server to edit.

name (str) – The new name of the server.

icon (bytes) – A bytes-like object representing the icon. See edit_profile() for more details. Could be None to denote no icon.

splash (bytes) – A bytes-like object representing the invite splash. See edit_profile() for more details. Could be None to denote no invite splash. Only available for partnered servers with INVITE_SPLASH feature.

region (ServerRegion) – The new region for the server’s voice communication.

afk_channel (Optional[Channel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

owner (Member) – The new owner of the server to transfer ownership to. Note that you must be owner of the server to do this.

verification_level (VerificationLevel) – The new verification level for the server.

Raises:

Forbidden – You do not have permissions to edit the server.

NotFound – The server you are trying to edit does not exist.

HTTPException – Editing the server failed.

InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the server and request an ownership transfer.

编辑:

你可能已经错过了什么,请复制正是这一点,注意有两大get_server调用。分别填写server_id和member_id。

await client.edit_server(server=client.get_server("server_id"), owner=client.get_server("server_id").get_member("member_id")) 
# you missed this part =>           |—————————————————————-———–—-| 

为了避免复制,你可以这样做:

server = client.get_server("server_id") 
await client.edit_server(server=server, owner=server.get_member("member_id")) 

提醒

你必须保持server=owner=一部分。

+0

这项工作? 'client.edit_server(discord.Server(317161621233467392),discord.Member(323512053862236161))' – ParkerSTP

+0

不,除非您尝试过并且另有其他说明。服务器是您发送消息的服务器吗?而该成员是服务器成员? – abccd

+0

无论哪种方式,你可以这样做,而不是'client.get_server(“服务器id”)'为服务器和'client.get_server(“服务器id”)。get_member(“会员id”)'为成员 – abccd