Describe the bug
I wanted to remove users roles including everyone role
The full goal of above snippet is to make a verifier modal that activates when a button is pressed and if the reponse text is not = to solvertextmain which is a captcha string(random 6 letter string) , if it matches i want allow user to message and assign him verified role but if it doesnt match i wanna mute the user for 2hours and when 2 hours passes i want to drop a message that reenables the user to use slash command and stuff
I want to add a role to user but i am getting this error
To Reproduce
import asyncio
from time import time
import discord
import os
from discord.ext import commands
import logging
import dotenv
import random
import string
from captcha.image import ImageCaptcha
import discord.utils
length=6
dotenv.load_dotenv()
token = str(os.getenv("TOKEN"))
solvertextmain = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(length))
file_name = "some_image"
#''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(20))
image = ImageCaptcha(width=280, height=90)
captcha = image.generate(solvertextmain)
image.write(solvertextmain, f"{file_name}.png")
listos=[]
config = None
verify_channel = None
mute_roleid =int(os.getenv("mute_roleid"))
verify_guild = int(os.getenv("verify_guild"))
verif_roleid= int(os.getenv("verif_roleid"))
everyoneroleid=int(os.getenv("everyoneroleid"))
kon=None
#globalvar
#loggerstart
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
#loggerend
client = discord.Bot()
@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('/start'):
await message.channel.send('Hello!')
@client.slash_command(desciption="starts-bot") # Create a slash command
async def wallet(ctx):
emchad =discord.Embed(title="Solve Captcha to Continue", color=0x2ea4ff)
imgfile = discord.File("some_image.png", filename="image.png")
emchad.set_image(url="attachment://image.png")
await ctx.respond("Please complete captcha to continue",embeds=[emchad],file=imgfile,ephemeral=True, view=verifierView())
Send a message with our View class that contains the button
class MyModal(discord.ui.Modal):
global kon
global listos
def init(self, *args, **kwargs) -> None:
super().init(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Enter your wallet address below"))
async def callback(self, interaction: discord.Interaction):
embed = discord.Embed(title="Wallet Address")
embed.add_field(name="Your Wallet Address ", value=self.children[0].value)
member=discord.Member
guild=client.get_guild(verify_guild)
verifrole=guild.get_role(verif_roleid)
print(verifrole)
await interaction.response.send_message(embeds=[embed], ephemeral=True),
await member.add_roles(verifrole)
kon=self.children[0].value
listos.append(kon)
print(listos)
output=open("file.txt", 'a')
for row in listos:
output.write(str(row) + '\n')
class MyView(discord.ui.View):
@discord.ui.button(label="Click here to enter your address")
async def button_callback(self, button, interaction):
await interaction.response.send_modal(MyModal(title="Enter wallet address below"))
class verifierView(discord.ui.View):
@discord.ui.button(label="Click here to enter captcha code")
async def button_callback(self, button, interaction):
await interaction.response.send_modal(verifierModal(title="Enter captcha below"))
async def disable_all_items(self) -> None:
await super().disable_all_items()
async def enable_all_items(self) -> None:
await super().enable_all_items()
class verifierModal(discord.ui.Modal):
def init(self, *args, **kwargs) -> None:
super().init(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Enter Captcha code below"))
@commands.has_permissions(kick_members=True,manage_roles=True)
async def callback(self, interaction: discord.Interaction):
print(self.children[0].value)
global solvertextmain
print(solvertextmain)
if solvertextmain in self.children[0].value:
await interaction.response.send_message("Enter your Address",ephemeral=True, view=MyView())
else:
await interaction.response.edit_message(view=None)
await interaction.followup.send(content="TRY AGAIN AFTER 2 HOURS",)
member=discord.Member
guild=client.get_guild(verify_guild)
print(guild.me)
role = guild.get_role(mute_roleid)
verifrole=guild.get_role(verif_roleid)
print(role)
roles1 = member.roles #save the member roles
print(roles1)
await member.edit(roles=[]) #remove all member roles
#bring back the old roles)
#role=discord.utils.get(member.guild.roles, name="Muted")
await member.add_roles(role)
await interaction.followup.send("You have has been muted!")
await asyncio.sleep(3600)
print(role.name)
if member.roles == "Muted":
await member.remove_roles(role)
await member.add_roles(verifrole)
await interaction.followup.send("You have been unmuted!")
await interaction.followup.send(content="NOW TRY AGAIN",view=verifierView())
####################################################################
if name == "main":
client.run(token)
Expected behavior
I wanted to remove users roles including everyone role
The full goal of above snippet is to make a verifier modal that activates when a button is pressed and if the reponse text is not = to solvertextmain which is a captcha string(random 6 letter string) , if it matches i want allow user to message and assign him verified role but if it doesnt match i wanna mute the user for 2hours and when 2 hours passes i want to drop a message that reenables the user to use slash command and stuff
I want to achieve results as shown in this Rapptz/discord.py#5937 but when i send this command await member.edit(roles=[]) erorr occurs
Screenshots
![image](https://user-images.githubusercontent.com/105252064/197327003-e8cabc5f-200c-4aaa-a66f-7a1ede07dcfb.png)
Additional context
Checklist
- [ Y] This is an issue with the build, not a spelling or grammar mistake.
- [ Y] I have the latest version of the guide.