I want a user to be able to report someone else, I am looking at the documentation, but I can't find a way to ping the user that sent the message, while also pinging the admin role in a admin channel.
import discord
from discord.ext import commands
import asyncio
import random
import json
client = commands.Bot(command_prefix="!")
@client.command()
async def Report(ctx, member : discord.Member,*, reason = "no reason provided"):
channel = client.get_channel(994788167699931206)
await channel.send(member.name f" has been reported by @{ctx.author.id}, because: " reason)
await channel.send("@Admin")
await channel.send("@Admin")
await channel.send("@Admin")
client.run("TOKEN")
CodePudding user response:
There are two ways I can recommend you can do this. The first way is to use the role id, which never changes even if you change the name. The other way would be to retrieve it by name, which would be useful if your bot is in multiple servers with the role of the same name, but does require an import.
# import required for method 2
from discord.utils import get
@client.command()
async def Report(ctx, member : discord.Member,*, reason = "no reason provided"):
channel = client.get_channel(994788167699931206)
# slight quality of life change for this, put all the variables in f-string
await channel.send(f"{member.name} has been reported by {ctx.author.mention}, because: {reason}")
# Method 1, this is how roles are formated
await channel.send("<@&123123>") # replace this with your id, type \@Admin to check the id
# Method 2, get role by name
admin_role = discord.utils.get(ctx.guild.roles,name="Admin")
await channel.send(admin_role.mention)