I have tried making a bot in discord.py and i cant figure out how to use discord.ext.
The part that doesn't work is this:
bot = commands.Bot(command_prefix='.')
@bot.command()
async def test(ctx, arg):
await ctx.channel.send(arg)
When I type .test whatever in discord nothing happens
Is it because of the api update? If so what do I need to change
This is the entire code:
import os
import discord
import asyncio
from dotenv import load_dotenv
from discord.ext import commands
from discord.ext import bot
bot = commands.Bot(command_prefix='$')
@bot.command()
async def test(ctx, arg):
await ctx.channel.send(arg)
load_dotenv()
token = os.getenv("TOKEN")
client = discord.Client()
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
f = open("muteMsg.txt", "r")
muteMsg = f.read()
f.close()
print('Message from {0.author}: {0.content}'.format(message))
id = message.author.id
if id == 0:
await message.delete()
if muteMsg == "1":
await message.channel.send(f"stfu {message.author.mention}")
elif message.content.startswith('good bot') or message.content.startswith('Good bot'):
await message.channel.send(':)')
elif message.content.startswith('bad bot') or message.content.startswith('Bad bot'):
await message.channel.send(':(')
elif message.content.startswith('.rickroll'):
await message.channel.send('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
elif message.content.startswith('.help'):
await message.channel.send('commands list:\n.help: shows this\n.rickroll: well youll have to try yourself\n')
elif message.content.startswith('.togglemutemsgs'):
if muteMsg == "0":
f = open("muteMsg.txt", "w")
f.write("1")
f.close()
await message.channel.send('mute messages on')
elif muteMsg == "1":
f = open("muteMsg.txt", "w")
f.write("0")
f.close()
await message.channel.send('mute messages off')
client = MyClient()
client.run(token)