Discord bot send message python code example
Example 1: send message discord.py
await message.channel.send("Your message")
Example 2: python discord
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
if message.author == self.user:
return
if message.content == 'ping':
await message.channel.send('pong')
client = MyClient()
client.run('token')
Example 3: discord.py
import discord
client = discord.Client()
@client.event
async def on_ready():
print('We have 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 4: how to make a discord bot send a message python
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='!!')
TOKEN = 'insert token here'
@client.event
def on_ready():
print('Ready. Logged in as: {0.user}'.format(client))
@client.command(brief='Echoes back what user says.')
async def echo(ctx, *, user_message):
await ctx.send('User said --> ' + user_message)
client.run(TOKEN)