1
votes

I'm trying to make a discord bot in python and I want to figure out how to give a role to myself, without notifying anything besides a conformation in the console.



import discord
import os

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 == '‎':
      # i want to give myself a role right here
      print('adding admin role to', message.author)
    print(message.author,message.content)



try:
    client.run(os.getenv("TOKEN"))
except discord.HTTPException as e:
    if e.status == 429:
        print("The Discord servers denied the connection for making too many requests")
        print("Get help from https://stackguides.com/questions/66724687/in-discord-py-how-to-solve-the-error-for-toomanyrequests")
    else:
        raise e

1
Please be a bit more clear in what you intend to achieve. By expecting a confirmation is a considered a notification in the console.Fishball Nooodles

1 Answers

0
votes

Get the role, using either utils.get on its name:

role = discord.utils.get(message.guild.roles, name=some_name)

or its ID:

role = message.guild.get_role(12345)

Then you can add the role to the member.

await message.author.add_roles(role)

(Also, please don't randomly give people admin if they send a specific message. That's going to end up being abused in some way.)