Certainly! Here's an example of a Discord command that could be considered a utility in Python:
python
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.command()
async def userinfo(ctx, member: discord.Member = None):
member = member or ctx.author
embed = discord.Embed(title=f"{member.name}'s User Info", color=member.color)
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name="Username", value=member.name, inline=False)
embed.add_field(name="Discriminator", value=member.discriminator, inline=False)
embed.add_field(name="ID", value=member.id, inline=False)
embed.add_field(name="Created At", value=member.created_at.strftime("%Y-%m-%d %H:%M:%S"), inline=False)
embed.add_field(name="Joined At", value=member.joined_at.strftime("%Y-%m-%d %H:%M:%S"), inline=False)
embed.add_field(name="Roles", value=', '.join(role.name for role in member.roles[1:]), inline=False)
embed.set_footer(text=f"Requested by {ctx.author.name}", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
bot.run('YOUR_DISCORD_TOKEN')
This command, when invoked with !userinfo, retrieves and displays information about a specific Discord user. The command takes an optional member argument, which can be used to specify the user for whom the information is requested. If no member is provided, it defaults to the user who invoked the command.
The command creates an embed message containing details such as the user's username, discriminator, ID, creation date, join date, and roles. The embed is then sent as a response in the Discord channel where the command was invoked.
Note: Make sure to replace 'YOUR_DISCORD_TOKEN' with your actual Discord bot token.