How do I get a role in Discord using a python bot?

I'm making a Discord bot on python 3.8. If you write some command in the discord bot, then it should "reward" the author of this message with a role. But this does not happen. What am I doing wrong?

P.S. The bot must give roles when sending it a message WITHOUT REACTIONS AND BUTTONS

Here is the code:

import discord
client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith("$ок"):
        on_member_join()
@client.event
async def on_member_join(member,message):
        role = discord.utils.get(member.guild.roles, id = 'id of role')
        await member.add_roles (message.author, role)
client.run("token")
Author: insolor, 2020-09-10

1 answers

I have my ready made code but I have with DB:

@commands.Cog.listener()
async def on_member_join(self, member):

    cursor.execute(f'SELECT wlc_role_t_or_f FROM public."myBD" WHERE guild_id = {member.guild.id};')
    on_or_off = cursor.fetchone()
    conn.commit()

    cursor.execute(f'SELECT wlc_role FROM public."myBD" WHERE guild_id = {member.guild.id};')
    role = cursor.fetchone()
    conn.commit()

    role_1 = member.guild.get_role(role[0])

    if f'{on_or_off[0]}' == str('True'):
        await member.add_roles(role_1)
    elif f'{on_or_off[0]}' == str('False'):
        pass

In your case, it will be:

@client.event()
async def on_member_join(member):
    role_1 = member.guild.get_role(15171165410)# ади роли которую будет получать новый юзер при входе на сервер
    await member.add_roles(role_1)

And if you want that would be on the team then similarly:

@client.command()
async def test(ctx):
    member = ctx.message.author
    role_1 = member.guild.get_role(15171165410)# ади роли которую будет получать юзер
    await member.add_roles(role_1)
 0
Author: xZartsust, 2020-09-10 19:57:30