on message discord py
@bot.event
async def on_message(message):
if message.content == "pong":
await message.channel.send('ping')
on message discord py
@bot.event
async def on_message(message):
if message.content == "pong":
await message.channel.send('ping')
discord.py message user
if message.content == "dm":
await message.channel.send("Dming user")
dm = await message.author.create_dm() # Creates a dm channel with the user
await dm.send("What you want to send") # Sends the user the message
discord.py get message text
#This is the same as Santinos answer, but not in plaintext ;-;
#When getting a message, you're going to need an abc.Messageable object - essentially an object where you can send a message in, for example a text channel, a DM etc.
#Example:
@bot.command()
async def getmsg(ctx, msgID: int): # yes, you can do msg: discord.Message
# but for the purposes of this, i'm using an int
msg = await ctx.fetch_message(msgID) # you now have the message object from the id
# ctx.fetch_message gets it from the channel
# the command was executed in
###################################################
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, member: discord.Member):
msg = discord.utils.get(await channel.history(limit=100).flatten(), author=member)
# this gets the most recent message from a specified member in the past 100 messages
# in a certain text channel - just an idea of how to use its versatility
how to detect the reaction to a message discord.py
@client.event
async def on_message(message):
#if the spotify command is triggered
#fetch from the API
spotifyEmbed = discord.Embed(title=resultName, ...)
spotifyEmbed.set_image(url=spotifyImgUrl)
spotifyMessage = await message.channel.send(embed=spotifyEmbed)
await spotifyMessage.add_reaction("⬅️")
await spotifyMessage.add_reaction("➡️")
@client.event
async def on_reaction_add(reaction, user):
if user != client.user:
if str(reaction.emoji) == "➡️":
#fetch new results from the Spotify API
newSearchResult = discord.Embed(...)
await reaction.message.edit(embed=newSearchResult)
if str(reaction.emoji) == "⬅️":
#fetch new results from the Spotify API
newSearchResult = discord.Embed(...)
await reaction.message.edit(embed=newSearchResult)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us