Making a Discord bot mention the command user and the target in a slap command

Need help with Discord bot mentions in a slap command

I’m trying to create a fun slap command for my Discord bot. What I want is for the bot to mention both me (the command user) and the person I’m targeting when I use the command. For example, if I type +slap @friendname, I want the bot to respond with something like @me slapped @friendname.

I’ve got some code set up, but I can’t figure out how to make the mentions work properly. Here’s what I’ve tried so far:

import discord
from discord.ext.commands import Bot

silly_bot = Bot(command_prefix='!')

@silly_bot.command()
async def bonk(ctx, victim: discord.Member):
    await ctx.send(f'{ctx.author.mention} bonked {victim.mention} with a rubber chicken!')

@silly_bot.event
async def on_ready():
    print('Silly Bot is ready to party!')
    await silly_bot.change_presence(activity=discord.Game(name='Bonking simulator'))

silly_bot.run('YOUR_TOKEN_HERE')

Any ideas on how to get the mentions working correctly? Thanks in advance for your help!

I’ve been messing with Discord bots for a while now, and your code looks spot-on for mentions. One thing I noticed though - you’re using ‘bonk’ in your code but mentioned ‘slap’ in your question. Make sure you’re using the right command when testing.

If it’s still not working, try this: instead of using f-strings, use Discord’s built-in Embed system. It’s a bit more work, but it gives you way more control over formatting and can sometimes fix weird mention issues. Here’s a quick example:

@silly_bot.command()
async def slap(ctx, victim: discord.Member):
    embed = discord.Embed(description=f'{ctx.author.mention} slapped {victim.mention} silly!')
    await ctx.send(embed=embed)

This approach has always worked for me. Give it a shot and let us know if it helps!

Your code appears to be correct for handling mentions in a Discord bot command. The ctx.author.mention and victim.mention should properly create clickable mentions for both the command user and the target. If you’re not seeing the expected behavior, there are a few things to check. Ensure your bot has the necessary permissions in the Discord server, verify that you’re using the correct command prefix (‘!’ in your code), and check if there are any error messages in your console when running the bot. If you’re still having issues after confirming these points, you might want to try using string interpolation with f-strings instead of the .format() method. This can sometimes resolve unexpected formatting issues.

hey dude, looks like ur almost there! the code u shared should actually work for mentions. make sure ur using the right prefix (‘+’ in ur question, ‘!’ in code). if it’s still not working, double-check ur bot’s permissions in the server. good luck!