fix commands & on_message
This commit is contained in:
parent
dc4e5e4912
commit
f38e77a9fa
1 changed files with 33 additions and 11 deletions
|
@ -8,17 +8,21 @@ from discord.ext import commands
|
|||
|
||||
import os
|
||||
|
||||
class Mybot(discord.Client):
|
||||
bot = commands.Bot(command_prefix='!')
|
||||
class Mybot(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def join_channel(self, message):
|
||||
channel = [x for x in self.get_all_channels() if x.name == "Général"][0]
|
||||
await self.join(channel)
|
||||
@commands.command()
|
||||
async def join_channel(self, ctx):
|
||||
channel = [x for x in self.bot.get_all_channels() if x.name == "Général"][0]
|
||||
await channel.connect()
|
||||
|
||||
@commands.command()
|
||||
async def ping(self, message):
|
||||
await message.channel.send('pong')
|
||||
|
||||
async def test(self, message):
|
||||
@commands.command()
|
||||
async def kadoc(self, ctx):
|
||||
quotes = [
|
||||
"Pour savoir s’y a du vent, il faut mettre son doigt dans le cul du coq.",
|
||||
"Y'a des méchants ?",
|
||||
|
@ -28,10 +32,8 @@ class Mybot(discord.Client):
|
|||
"Elle est où la poulette ?",
|
||||
"Mooordu! Mooordu! Mordu mordu mordu mordu la ligne !!!!",
|
||||
]
|
||||
|
||||
response = random.choice(quotes)
|
||||
await message.channel.send(response)
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
async def on_message(self, message):
|
||||
print(message.content)
|
||||
|
@ -59,8 +61,28 @@ class Mybot(discord.Client):
|
|||
|
||||
def main():
|
||||
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
|
||||
client = Mybot()
|
||||
client.run(token)
|
||||
bot = commands.Bot(command_prefix='!')
|
||||
|
||||
@bot.event
|
||||
async def on_message(message):
|
||||
print(message.content)
|
||||
if message.author == bot.user:
|
||||
return
|
||||
if message.content == 'pwet':
|
||||
await message.channel.send('pong')
|
||||
else:
|
||||
if bot.user in message.mentions and len(message.mentions) < 3:
|
||||
path = '/tmp/%s.log' % message.channel
|
||||
with open(path, 'r') as f :
|
||||
lines = f.read().splitlines()
|
||||
with open(path, 'a') as f :
|
||||
f.write(message.content + '\n')
|
||||
response = random.choice(lines).replace(str(bot.user.id), str(message.author.id))
|
||||
await message.channel.send(response)
|
||||
await bot.process_commands(message)
|
||||
|
||||
bot.add_cog(Mybot(bot))
|
||||
bot.run(token)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue