Prisoner Role, Discord.py 1.5.0a - discord.py

I'm trying to do a bot that picks up all roles from user, send a message that mention all roles in a channel, so the bot need remove all roles and add a 'Prisoner' role and send a reason for the prison. How do I do this?
I'm trying to do this command for 3 days, but nobody could help me.

You can try this for deleting all roles and adding prisoner role:
#client.command()
async def prison(ctx, member: discord.Member):
member_roles = []
for role in member.roles:
member_roles.append(role)
await member.remove_roles(role)
member_roles = ', '.join(member_roles)
await ctx.send(f'{member.mention} is in prison. His {member_roles} roles are deleted.')
prisoner = discord.utils.get(ctx.guild.roles, name='Prisoner')
await member.add_roles(prisoner)
After you create the Prisoner role, change the permissions of this role for all the channels except for Prison channel in Discord.
Note: There could be syntax problems in my code because I'm on mobile right now. If any problem raises, just comment.

Related

Discord Integer delete mention <#Deleted-Role>

I'm wondering if any of you guys can figure out how i could use my role : Name : Color Magenta. Id. 855179067388461076
Known Issue: Discord have limitation of integer maximum lenght. I believe.. that's what i know..
#bot.command()
async def Shop(ctx):
roleId = "855179067388461076>"
ShopEM = discord.Embed(title=f"🢃 BASIC COLORS SHOP 🢃", color=0xff5555)
ShopEM.add_field(name=f"1) Magenta", value=f'<#&' + (roleId), inline=True)
ShopEM.add_field(name=f"2) khaki ", value=f"<#&1075540590604853278>", inline=False)
ShopEM.add_field(name=f"3) Purple", value=f"<#&1075540578072273006>", inline=False)
ShopEM.add_field(name=f"4) Gray", value=f"<#&1075540541195960400>", inline=True)
ShopEM.add_field(name=f"5) Olive ", value=f"#&1075540533457461379>", inline=False)
ShopEM.add_field(name=f"6) Teal", value=f"<#&1075540547021840404>", inline=False)
ShopEM.add_field(name=f"PRICE", value="")
await ctx.send(embed=ShopEM)
Output :
Are you sure:
that the bot has permissions to mention those roles?
that those IDs are the correct roles for this server?
My code below, very similar to yours, works absolutely fine. I only got deleted-role when I entered in numbers that were made up or for roles not in this server.
#bot.command()
async def shop(ctx):
# list of tuples to iterate over with the role name and then role ID
roles = [
("bots", "1065670055507005128"),
("server booster", "1068466410612867541"),
("human", 1064550904461795018),
("admin", 813738863871787428)
]
shop_em = discord.Embed(title="🢃 BASIC COLORS SHOP 🢃", color=0xff5555)
# iterate over the roles and add them to the embed
for role in roles:
shop_em.add_field(name=role[0], value=f"<#&{role[1]}>", inline=True)
await ctx.send(embed=shop_em)
Note: Putting the IDs as ints or strings didn't matter at all. For example, I use both here and there weren't issues with either.
Example of it working:

Bot is unresponsive even when a "message.channel.send" await is called. What is wrong?

This discord.py project I have been working on in the past few days has given me nothing but trouble. To state what the issue is here. Basically the entire application is unresponsive, even when every await and every intent is enabled(on the commands.Bot main.py this is just an extension). I have tried every solution possible. I tried retyping keys and values for the dictionaries. And I even removed the embedded messages and replaced them with normal string messages. And I still got nothing. Here is a little snippet of the "problem". Anyways, I'd appreciate it if I could get some help on this?
#commands.Cog.listener()
async def on_message(self, message, member:discord.Member=None):
ARI=discord.utils.get(message.guild.roles,name=teamnames['ARI'])
ATL=discord.utils.get(message.guild.roles,name=teamnames['ATL'])
if message.content.startswith('<:ARI:844709003871387648> sign'):
member = message.mentions[0]
if ARI or ATL in member.roles:
embed=discord.Embed(title="Signing Failed", description=f"**{member.mention} Wasnt Signed due to there being another team role in that users role. If this is incorrect, have this user either: \nAsk for Release or Demand from the team that they are currently roled as. . .**")
await message.channel.send(embed=embed)
else:
embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the <:ARI:844709003871387648> as the **`{len(ARI.members)}`** Player Signed Accordingly. If this was an error use command: <:ARI:844709003871387648> **`Release #user.mention`** To release the player of your initially signed roster.")
await member.add_roles(ARI)
await message.channel.send(embed=embed)
Resolved the issue by reverting to dictionary keys and values, but a new error is now showing. And the bot is still for some reason unresponsive? Snippet below:
#commands.Cog.listener()
#commands.has_any_role('Franchise Owner', 'General Manager', 'Head Coach')
async def on_message(self, message):
if 'have signed' in message.content:
member = message.mentions[0]
teamemojis = ["ARI", "ATL", "BAL", "BUF", "CAR", "CHI", "CIN", "CLE"]
teamsids = [784827425422573608, 784827426093793330, 784827440324804639, 784827439221047317, 784827427029385246, 784827427796025364, 784827441205477386, 784827442174623745,]
teams=[]
if teamsids.id in teamsids:
teams.append(teamsids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsids.index(int(step4))
print(step5)
emote=discord.utils.get(message.guild.emojis,name=teamemojis[step5])
team = discord.utils.get(message.guild.roles,id=int(step4))
pass
if team not in message.author.roles:
print('return')
return
elif team in message.author.roles:
print('pass')
pass
if team not in member.roles:
for role in message.author.roles:
role.name == team.name
await member.add_roles(role, reason="Signed by the Bot!")
embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the {str(emote)} accordingly. If this was a mistake, please refer to the `have released` Command in the bot commands**")
embed.set_thumbnail(url=emote.url)
await message.channel.send(embed=embed)
elif team in member.roles:
await message.channel.send("**Cannot sign this user, as this user is already signed!**")
return
For an on_message event. Read the docs here: https://discordpy.readthedocs.io/en/stable/faq.html#why-does-on-message-make-my-commands-stop-working
Adding the line:
await bot.process_commands(message)
at the bottom of the on_message event should make it function correctly again

Create a invite

I am trying to make a command to invite myself to all servers of my bot is what can I do? I did his.
#client.command()
async def inviteall(ctx):
guild=client.guilds
for i in list(client.guilds):
invite = await ctx.guild.create_invite(reason=reason)
await ctx.send(invite)
The Problem here; You are trying to create an invite for the whole guild (which isn't possible). You can only create invites for specific channels (where your bot has create invite permissions).
Also you are trying to do this with ctx which would try to create an invite in the guild the message was sent from.
Another thing I noticed is that you are trying to send the variable invite and not the url.
Example:
#client.command()
async def inviteall(ctx):
# guild=client.guilds You can delete this if you don't need it somewhere else
for i in list(client.guilds):
channel = discord.utils.get(i, name="CHANNEL_NAME")
# You can either you this /\ or this \/ (Both will not work)
channel = client.get_channel(CHANNEL_ID)
invite = await channel.create_invite(reason=reason) # If you haven't defined 'reason' before
# this will get a problem
await ctx.send(invite.url)
You can only create an invite to specific channels. A good way to do this is to get an invite to the guild's system_channel. If it is None, you can try for each channel of the guild.
async def inviteToGuild(guild, reason):
systemChannel = guild.system_channel
if systemChannel is not None:
invite = await systemChannel.create_invite(reason=reason)
else:
# For each channel of the guild, try to create an invite
return invite
Then just execute this function for all guilds in your client.guilds!

How do I make a lockdown command for a specified role?

You may have seen my previous question (How do I make a lockdown command?), where I asked about how to lockdown specified channel. But that command only locked down the # everyone role. My server has millions of roles and channels made for other roles, so I want to know how to change ctx.guild.default_role to something where you specify the role and the channel locks down for that role. Current command:
#commands.command()
#commands.has_permissions(manage_channels=True)
async def lockdown(self, ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send(ctx.channel.mention + " ***is now in lockdown.***")
You can simply pass the role as an argument
async def lockdown(self, ctx, role: discord.Role): # `RoleConverter` will automatically convert it to a `discord.Role` instance
await ctx.channel.set_permissions(role, send_messages=False)
await ctx.send(ctx.channel.mention + " ***is now in lockdown.***")
You can invoke it by mentioning the role, by putting the role ID or simply by passing the name of the role

Set username as argument

Earlier, I asked a question which was fixing some broken code. But the code specified changed the role of the author.
async def ruleBreak(ctx, arg):
member = await ctx.message.author
role = discord.utils.get(member.guild.roles, name="RuleBreakers")
await discord.Member.add_roles(member, role)
However, I want to set a specified user to get the role, not the author. I've thought about removing the send part on line 2.
Please help.
Thanks in advance!
Your second line is saying that the member who should get the role is the member who invokes the command. For this you can use add_roles() which takes the role you want to give as an arguments. You can specify a recipient and role like so !addrole #someperson #thisrole
#client.command()
async def addrole(ctx, user: discord.Member, role: discord.Role):
await user.add_roles(role)
await ctx.send(f"I gave {user.name} the role {role.name}")

Resources