因此,我制作了一个禁止在名单上列出人员的漫游器。该列表是用户的ID。向他们发送消息的第一部分有效,但禁止它们的第二部分无效。
if message.content.startswith('purge') and message.author.id == "317026781708288024":
logID()
msg = "Hey something bad happened and you got banned good luck the server is down now"
f = open("ID.log","r")
lines = f.readlines()
for line in lines:
member = await client.get_user_info(line)
try:
await client.send_message(member, msg)
except Exception:
pass
await client.ban(member, delete_message_days=7)
f.close()
我得到的错误是:
Ignoring exception in on_message
Traceback (most recent call last):
File "/home/jacob/.local/lib/python3.6/site-packages/discord/client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "Evster.py", line 141, in on_message
await client.ban(member, delete_message_days=7)
File "/home/jacob/.local/lib/python3.6/site-packages/discord/client.py", line 1735, in ban
yield from self.http.ban(member.id, member.server.id, delete_message_days)
AttributeError: 'User' object has no attribute 'server'
答案 0 :(得分:2)
discord.py
使用两个不同的类来表示帐户User
和Member
。 Member
是User
的子类。 User
对象代表一个不和谐帐户(您,我,一个机器人),而Member
对象代表一个特定服务器上帐户的状态,并包括昵称,角色,权限等。>
您不能禁止User
,因为User
对象不包含有关将要禁止它们的服务器的任何信息。相反,您需要获取该服务器的成员对象。幸运的是,Server
对象的方法很简单
member = message.channel.server.get_member(line)