discord.py Mention user by name

2024/10/6 11:15:18

I am trying to mention a user by their name in discord.py. My current code is:

@bot.command(name='mention')
@commands.has_role(OwnerCommands)
async def mention(ctx, *, member: discord.Member):memberid = member.idawait ctx.message.delete()await ctx.send('<@{}>'.format(memberid))

But it does not work. How do I do this?

Edit, I found an answer.

Answer

It is rather straight forward member.mention

@bot.command(name='mention')
@commands.has_role(OwnerCommands)
async def mention(ctx, *, member: discord.Member):await ctx.message.delete()await ctx.send(member.mention)
https://en.xdnf.cn/q/119427.html

Related Q&A

Python unexpected EOF while parsing : syntax error

I am trying to do a simple toto history with a dictionary and function however I have this funny syntax error that keeps appearing that states "unexpected EOF while parsing" on the python she…

How can I read part of file and write the rest to another file?

I have multiple large csv file. How can I read part of each file and write 10% of the data/rows to another file?

Encryption/Decryption - Python GCSE [duplicate]

This question already has an answer here:Encryption and Decryption within the alphabet - Python GCSE(1 answer)Closed 8 years ago.I am currently trying to write a program, for school, in order to encryp…

Convert decimal to binary (Python) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Kivy Digital Clock Issues

Im trying to add a digital clock to my Kivy program, it seems to be having trouble.Here is the .py:import kivykivy.require(1.10.0)from kivy.lang import Builder from kivy.uix.screenmanager import Screen…

Read a file name and create a column with it [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 4…

Python : T test ind looping over columns of df

My dataframe is composed of accounting variables and a dummy variable that allows me to identify two types of company. I would like to perform a t-test for every column of my dataframe in order to comp…

I want to understand which line of code outputs **none** in the function

The last line of the output is none can someone explain why pls def just_lyrics():print ("i am a bad coder")print (" i keep trying to learn everday")def double_lyrics():just_lyrics(…

How to clear python console (i.e. Ctrl+L command line equivalent)

OS = Linux[boris@E7440-DELL ~]$ uname -a Linux E7440-DELL 3.17.4-200.fc20.x86_64 #1 SMP Fri Nov 21 23:26:41 UTC 2014 x86_64 x86_64 x86_64 GNU/LinuxFrom python console (Spyder 2.2.4, Python 2.7.5 64bits…

Floating point accuracy in python

Any reason why c shouldnt equal 0.321?>>> from math import ceil >>> a = 123.321 >>> b = a % 60 >>> b 3.320999999999998 >>> ceil(b) 4.0 >>> c = cei…