How to make discord bot ping users using discord.py [closed]

2024/7/7 6:34:01

I am coding a discord bot and for one of the commands I want the bot to ping the user that sent the command. I'm using python 3.6.6

Answer

Here is one example how you can ping (mention) the user who sent a specific message (command):

import discordclass MyClient(discord.Client):async def on_ready(self):print('Logged on as', self.user)async def on_message(self, message):# don't respond to ourselvesif message.author == self.user:returnif message.content == '$the_ping_cmd':await message.channel.send('Pinging {}'.format(message.author.mention))client = MyClient()
client.run('token')
https://en.xdnf.cn/q/120515.html

Related Q&A

how to edit hostname file using fabric

I have change my hosts file,so how to change hostname.my system is ubuntu. eg my hosts file:192.168.0.100 host1.mydomain.com 192.168.0.101 host2.mydomain.comI wanna the hostname file under /etc/hostnam…

functions and indentation in python [duplicate]

This question already has answers here:How do I get ("return") a result (output) from a function? How can I use the result later?(4 answers)Closed 3 days ago.Im taking a tutorial in udemy t…

How do I define a method to store a collection (e.g., dictionary)?

Im a beginner working on a library management system and theres something I cant get my head around. So I have a Books class that creates new book records. class Books:def __init__(self, title=None, au…

Python Regex punctuation recognition

I am stumped by this one. I am just learning regular expressions and cannot figure out why this will not return punctuation marks.here is a piece of the text file the regex is parsing:APRIL/NNP is/VBZ …

cant find brokenaxes module

I want to create a histogram with broken axes and found that there must be a module doing this called brokenaxes that works together with matplotlib (source) . Anyway, when I trie to import the modul…

Python-Pandas While loop

I am having some trouble with the DataFrame and while loop:A B 5 10 5 10 10 5I am trying to have a while loop that:while (Column A < Column B):Column A = Column A + (Column B / 2)Colu…

split an enumerated text list into multiple columns

I have a dataframe column which is a an enumerated list of items and Im trying to split them into multiple columns. for example dataframe column that looks like this:ID ITEMSID_1 1. Fruit 12 oranges 2…

Python using self as an argument [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable…

how to shuffle questions in python

please anyone help me i have posted my whole work down can anyone tell me how to shuffle theses five questions it please i will be very thankful.print("welcome to the quiz") Validation = Fals…

Selenium python do test every 10 seconds

I am using selenium (python) testing and I need to test my application automatically every 10 seconds.How can I do this?