Discord Integer delete mention <#Deleted-Role> - discord.py

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:

Related

How to the list of people that has a certain role

I searched for it, but didn't find anything that could really help. Basically, I would like that when I run .highrank in a discord channel, the bots gives me a list of the people that have this role.
This is the current code I have:
#client.command()
async def highrank(ctx):
role =
await ctx.send(role.members)
I do not know how to make sure that this will give me a list of the people with the high rank role in the server.
Edit: I found this, but I only get the bot name and ID when I do the command, and only if the bot has the role.
#client.command(pass_context=True)
async def members(ctx, *args):
server = ctx.message.guild
role_name = (' '.join(args))
role_id = server.roles[0]
for role in server.roles:
if role_name == role.name:
role_id = role
break
else:
await ctx.send("Role doesn't exist")
return
for member in server.members:
if role_id in member.roles:
await ctx.send(f"{member.display_name} - {member.id}")
#client.command()
async def userrole(ctx, role: discord.Role):
# this will give the length of the users in role in an embed
members_with_role = []
for member in role.members:
members_with_role.append(member.name)
embed = discord.Embed(title=f"**Users in {role.name}: **{len(members_with_role)}", description="\n ".join(member.mention for member in role.members)
await ctx.send(embed=embed)
To get a role by its ID:
ctx.guild.get_role(123456789)
You would replace 123456789 with the role id you get by right-clicking the role (with Developer Mode enabled in Discord).
#client.command()
async def highrank(ctx):
HIGHRANK_ROLE_ID = 123456789 # replace this with your role ID
role = ctx.guild.get_role(HIGHRANK_ROLE_ID)
await ctx.send(role.members)
Alternatively, you can use ctx.guild.roles and locate the role by name using a helper such as discord.utils.find.
#client.command()
async def highrank(ctx):
# replace the role name with your "High Rank" role's name
role = discord.utils.find(lambda m: m.name == 'High Rank', channel.guild.roles)
await ctx.send(role.members)

Is there a way to record the specific user of a command for future use without a database?

So I'm working on a discord bot using discord.py and I'm trying to create a bot for the moderation team in a server, the bot will swap the 'Moderator' role with a 'Leave of absence' role for when they're not active, however the code I have come up with has a slight loopholing problem that I just can't figure out, the code for the commands is this
...
#client.command()
#commands.has_role('Moderator')
async def sl(ctx, member: discord.Member = None):
if not member:
member = ctx.author
loa = ctx.guild.get_role(848032714715561985)
mod = ctx.guild.get_role(848032880709074944)
await member.add_roles(loa)
await member.remove_roles(mod)
await ctx.send("I have filed your Leave, take care, we look forward to your return!")
#client.command()
async def sr(ctx, member: discord.Member = None):
if not member:
member = ctx.author
mod = ctx.guild.get_role(848032880709074944)
loa = ctx.guild.get_role(848032714715561985)
await member.add_roles(mod)
await member.remove_roles(loa)
await ctx.send("Welcome back!")
...
as you can see anyone could use the second command to just give themselves a moderator role, I can't set the second command to be moderator only use as the moderator will no longer have said role from using the first command, I'm racking my brain to think of a work around i.e. logging the command users id to a whitelist and having only those whitelisted id's be able to use the second command, I've done many googlesearches for this but have come back with no results, any suggestions would be appreciated, please forgive that this question is a bit lengthy and I'm still very new to coding in general so any help at all, even if you don't fully understand what I'm blabbering on about would be very appreciated, thank you.
Check for the loa role in the command (ex):
mod = None
for role in ctx.author.roles:
if role.id == 848032714715561985: mod = True
if mod:
#your code here
So from your question, I'm guessing that you would like to code basically a "storage" file and make sure the person on the leave of absence was previously a moderator.
What you could do is create a csv file, for example records.csv (in the same folder as your main .py file of course), and every time someone calls the sl command, the program will record the user that used it.
import csv
#client.command()
#commands.has_role('Moderator')
async def sl(ctx, member: discord.Member = None):
if not member:
member = ctx.author
loa = ctx.guild.get_role(848032714715561985)
mod = ctx.guild.get_role(848032880709074944)
await member.add_roles(loa)
await member.remove_roles(mod)
file = open("records.csv", "w")
file.writelines(str(ctx.author.id))
file.close()
await ctx.send("I have filed your Leave, take care, we look forward to your return!")
#client.command()
async def sr(ctx, member: discord.Member = None):
if not member:
member = ctx.author
mod = ctx.guild.get_role(848032880709074944)
loa = ctx.guild.get_role(848032714715561985)
found = False
with open('records.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
if row[0] == str(ctx.author.id):
found = True
break
if found = False:
await member.add_roles(mod)
await member.remove_roles(loa)
await ctx.send("Welcome back!")
else:
await ctx.send("We do not have history of you having a moderator role.")
Are you running the program through an online environment like Repl.it? If so, this may not be the best way to approach this problem since people would have access to your this records.csv file (which you may not care about but just in case). If you are running the program through your desktop file directories, then there should be no privacy concerns.

Command for mp a role - Discord.py

I want I i want to make an command that mp a role when you send a message such as "#role, message"
Here is my code :
#bot.command()
async def DM(ctx, role : discord.Role.members, content):
channel = await role.create_dm()
await channel.send(content)
Thank you in advance
I assume you mean by mp you mean mass ping. Regardless to have a command like this would almost certainly be painfully ratelimited (10 user dms per 10 seconds), but let's say hypothetically you don't care, this is how I would approach it
(this requires the members intent)
#bot.command()
async def DM(ctx, role : discord.Role.members, content):
for member in ctx.guild.members:
if role in member.roles:
channel = await member.create_dm()
await channel.send(content)
first of all thank you for your help! But from my side it seems that the code doesn't work ^^
Besides this order will not be used to harass people lol Just to send a newspaper when these people will have chosen a role beforehand
The Error :

How do you make a discord bot that send a message if another user send a message? discord.py

Hi I need help in making a bot that can send a message if a specific user send one.
ex.
Arikakate: hi guys
Bot: yo wassup
this is the code i managed to write but doesn't work:
#client.event
async def on_message(message):
me = '<user id>'
if message.author.id == me:
await message.channel.send("yo wassup")
else:
return
It's not working because the ID's are integers, also message.author can be None if you don't have intents.members enabled
#client.event
async def on_message(message):
me = 6817239871982378981
if message.author.id == me:
await message.channel.send('yo wassup')
What are intents?
Discord requires users to declare what sort of information (i.e. events) they will require for their bot to operate. This is done via form of intents.
You can read more about intents here
What are privileged intents?
With the API change requiring bot authors to specify intents, some intents were restricted further and require more manual steps. These intents are called privileged intents.
How do I enable intents?
intents = discord.Intents.default()
bot = commands.Bot(..., intents=intents)
# or if you're using `discord.Client`
client = discord.Client(intents=intents)
How do I enable privileged intents?
intents = discord.Intents.all() # If you want both members and presences
# if you only want members or presences
intents = discord.Intents.default()
intents.members = True
Also make sure to enable privileged member intents in the developer portal. here's how
Creating a command that checks if the author of the message id is '2130947502309247'.
If it isn't the bot sends a message that says "That id does not belong to you", if the id does belong to the author the bot says "That id belong to you"
#client.command()
async def test(ctx):
if ctx.author.id != 2130947502309247:
await ctx.send("That id does not belong to you")
else:
await ctx.send("That id belong to you")
Quite simple

Prisoner Role, Discord.py 1.5.0a

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.

Resources