Reputation: 21
As example, I want the bot to send the users name like: "!hi Jake" bot: "Jake"
So the bot will only say "Jake" "not the entire command" if someone can help me with this I would highly appreciate that!
Upvotes: 1
Views: 796
Reputation: 1639
If you want it to simply respond with the text that is passed in with the command, then you can do this:
@bot.command()
async def hi(ctx, user : str):
await ctx.send(user) # !hi Jake will return Jake
However, if you want it to respond using the Member
object which contains a lot of information about the member object passed in, then you can do this:
@bot.command()
async def hi(ctx, user : discord.Member):
await ctx.send(f"{user.name}") # or user.mention or user.display_name
Keep in mind that this second solution will only work if the name passed in is the name of someone in the server that you're calling the command in. I think for what you want, the first solution should work just fine.
Edit: After looking at ur comment, you need to use your on_message
event to check whether a message starts with hi
. If it does, then it'll print the name that comes after it. Copy paste this code:
@client.event
async def on_message(message):
if (message.author == client.user):
return
if message.content.startswith('hi'):
words = message.content.split()
for i in words:
if i == 'hi':
name = words.index(i) + 1
embed = discord.Embed(title=f"hi {words[name]}", description=f"{random.randint(1,100)}")
await message.channel.send(embed=embed)
await client.process_commands(message)
Upvotes: 1