Answer the question
In order to leave comments, you need to log in
Discord Bot issuing a role on the required message?
import discord
from discord import utils
import const
from discord.ext import commands
class MyClient(discord.Client):
async def on_ready(self):
print('Загрузился {0}!'.format(self.user))
async def on_message(self, message):
if message.content.startswith('1'):
channel = message.channel
user=message.author.id
await bot.add_roles(user,898612321755230260)
bot = MyClient()
bot.run(const.TOKEN)
Answer the question
In order to leave comments, you need to log in
add_roles is a method of the discord.Member class, not discord.Client. Accordingly, it must be called from the correct object. In this case, the easiest way to get the Member instance of the sender of this message is to refer to message.author:
await message.author.add_roles(role)
In this case, role should not be a role id, but a discord.Role object. Which can be obtained by the get_role method of the discord.Guild class. And for Member it can be obtained from the guild field.
As a result, it turns out that we need:
author = message.author
guild = author.guild
role = guild.get_role(898612321755230260)
await author.add_roles(role)
await message.author.add_roles(message.author.guild.get_role(898612321755230260))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question