Reputation: 23
I have this code and i am really curious about why it is not working. The problem is in k = discord.Server.get_member(j)
it says
"TypeError: get_member() missing 1 required positional argument: 'user_id'".
This code uses discord.py:
@client.event
async def on_message(message):
if message.content.startswith('/sendpm'):
print(message.author)
j = message.content.replace('/sendpm ', '')
print(j)
j = j.replace('@', '')
j = j.replace('<', '')
j = j.replace('>', '')
j = j.replace('!', '')
print(l)
k = discord.Server.get_member(j) #problem is here
await client.send_message(await client.start_private_message(k), spammsg)
await client.send_message(message.channel, 'sent' + message.author.mention)
Upvotes: 2
Views: 5487
Reputation: 19352
This code is accessing a method of discord.Server
as if it was a static method:
k = discord.Server.get_member(j)
Function get_member
is defined as:
def get_member(self, user_id):
It accepts self
as the first argument because it is meant to be called on an instance, e.g.:
server = discord.Server()
server.get_member(user_id)
Whether that is the correct way to get a Server
instance I do not know. This example seems to have a different way to get to a server instance:
@client.event async def on_member_join(member): server = member.server fmt = 'Welcome {0.mention} to {1.name}!' await client.send_message(server, fmt.format(member, server))
Upvotes: 3