Python Question

Discord API, get_member(user_id) errors

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

async def on_message(message):
if message.content.startswith('/sendpm'):
j = message.content.replace('/sendpm ', '')
j = j.replace('@', '')
j = j.replace('<', '')
j = j.replace('>', '')
j = j.replace('!', '')
k = discord.Server.get_member(j) #problem is here
await client.send_message(await client.start_private_message(k), spammsg)
await client.send_message(, 'sent' +

Answer Source

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()

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:

async def on_member_join(member):
    server = member.server
    fmt = 'Welcome {0.mention} to {}!'
    await client.send_message(server, fmt.format(member, server))