discord.py message.content code example
Example 1: discordpy base code
import discord
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
client.run('your token here')
Example 2: discord.py message user
if message.content == "dm":
await message.channel.send("Dming user")
dm = await message.author.create_dm()
await dm.send("What you want to send")
Example 3: discord.py get message text
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):
msg = await ctx.fetch_message(msgID)
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, member: discord.Member):
msg = discord.utils.get(await channel.history(limit=100).flatten(), author=member)