Closed ioandev closed 7 years ago
http://discordpy.readthedocs.io/en/latest/api.html#discord.Client.add_roles and I suggest reading the docs before asking something like that -> http://discordpy.readthedocs.io/en/latest/api.html
Great!
Thank you @Eternity71529
Hi.. sorry but it doesn't seem to work.
My bot has permissions to change roles.
It says in the documentation The Member object is not directly modified afterwards until the corresponding WebSocket event is received.
i'm waiting 5s + and nothing happens.
The code checks if the user has permission correctly (as far as i'v eseen), but add_roles and remove_roles doesn't seem to be doing anything.
my code:
#helper method
def get_channel(channel_name):
all_channels = client.get_all_channels()
channelToBroadcast = None
for channel in all_channels:
if channel.name == channel_name and channel.type == ChannelType.text:
channelToBroadcast = channel
return channelToBroadcast
def get_role(role_name, server):
for role in server.roles:
if role.name == role_name:
return role
return None
##in message listener:
if message.content == '!dj':
music_channel = get_channel("music")
if music_channel is not None:
member_permissions = music_channel.permissions_for(message.author)
has_dj_role = member_permissions.send_messages
print(has_dj_role)
message_sent = None
#add the role
if not has_dj_role:
dj_role = get_role("DJ", message.server)
client.add_roles(message.author, [dj_role])
fmt = '{0.mention} esti DJ si ai access la canalul #music!'
to_send = fmt.format(message.author)
message_sent = await client.send_message(message.channel, to_send)
else:
fmt = '{0.mention} esti deja DJ!'
to_send = fmt.format(message.author)
message_sent = await client.send_message(music_channel, to_send)
await asyncio.sleep(5)
await client.delete_message(message_sent)
elif message.content == "!nodj":
music_channel = get_channel("music")
if music_channel is not None:
member_permissions = music_channel.permissions_for(message.author)
has_dj_role = member_permissions.send_messages
print(has_dj_role)
message_sent = None
#
if has_dj_role:
dj_role = get_role("DJ", message.server)
print(type(dj_role))
client.remove_roles(message.author, [dj_role])
fmt = '{0.mention} nu mai esti DJ!'
to_send = fmt.format(message.author)
message_sent = await client.send_message(message.channel, to_send)
else:
fmt = '{0.mention} nu esti DJ!'
to_send = fmt.format(message.author)
message_sent = await client.send_message(message.channel, to_send)
await asyncio.sleep(5)
await client.delete_message(message_sent)
FrostLuma, Painezor and Jayden helped me solve this on discord.
Solution:
await client.add_roles
, await client.delete_roles
.
Hi, there seems to be no way to add a role for a user when she types something in chat.