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
|
import os
|
||||||
|
|
||||||
class Mybot(discord.Client):
|
class Mybot(commands.Cog):
|
||||||
bot = commands.Bot(command_prefix='!')
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
async def join_channel(self, message):
|
@commands.command()
|
||||||
channel = [x for x in self.get_all_channels() if x.name == "Général"][0]
|
async def join_channel(self, ctx):
|
||||||
await self.join(channel)
|
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):
|
async def ping(self, message):
|
||||||
await message.channel.send('pong')
|
await message.channel.send('pong')
|
||||||
|
|
||||||
async def test(self, message):
|
@commands.command()
|
||||||
|
async def kadoc(self, ctx):
|
||||||
quotes = [
|
quotes = [
|
||||||
"Pour savoir s’y a du vent, il faut mettre son doigt dans le cul du coq.",
|
"Pour savoir s’y a du vent, il faut mettre son doigt dans le cul du coq.",
|
||||||
"Y'a des méchants ?",
|
"Y'a des méchants ?",
|
||||||
|
@ -28,11 +32,9 @@ class Mybot(discord.Client):
|
||||||
"Elle est où la poulette ?",
|
"Elle est où la poulette ?",
|
||||||
"Mooordu! Mooordu! Mordu mordu mordu mordu la ligne !!!!",
|
"Mooordu! Mooordu! Mordu mordu mordu mordu la ligne !!!!",
|
||||||
]
|
]
|
||||||
|
|
||||||
response = random.choice(quotes)
|
response = random.choice(quotes)
|
||||||
await message.channel.send(response)
|
await ctx.send(response)
|
||||||
|
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
print(message.content)
|
print(message.content)
|
||||||
if message.author == self.user:
|
if message.author == self.user:
|
||||||
|
@ -59,8 +61,28 @@ class Mybot(discord.Client):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
|
token = "NjI3MTM3NDY1MDA5ODMxOTQ2.XY4Raw.pw8sAen3bNR5aYsoTChQOudM0L8"
|
||||||
client = Mybot()
|
bot = commands.Bot(command_prefix='!')
|
||||||
client.run(token)
|
|
||||||
|
@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__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue