discord.py edit_server 函数示例
discord.py edit_server function example
早些时候,我尝试使用函数 edit_server,如 discord.py 文档中所列:http://discordpy.readthedocs.io/en/latest/api.html?highlight=ownership,但无法弄清楚如何使用它。我想用它来发出将所有权转让给另一个用户的命令。我的代码:
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
正如文档所述,server
和 owner
采用 discord.Server
和 discord.Member
对象,您不能只传递其 str
表示id.
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=
部分。
早些时候,我尝试使用函数 edit_server,如 discord.py 文档中所列:http://discordpy.readthedocs.io/en/latest/api.html?highlight=ownership,但无法弄清楚如何使用它。我想用它来发出将所有权转让给另一个用户的命令。我的代码:
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
正如文档所述,server
和 owner
采用 discord.Server
和 discord.Member
对象,您不能只传递其 str
表示id.
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=
部分。