如何制作Python Discord笑话机器人?

时间:2019-01-18 02:26:38

标签: python bots discord

我正在尝试制作一个Python Discord机器人,该机器人可以从列表中随机地讲和讲笑话。

我尝试定义一个笑话和答案列表以及我的代码。 *我包括一些老套的笑话

import discord
import random

client = discord.Client()
jokes = ["What do you call a dull pencil?", "What do you call a cow with no legs?", "", "", ""]
answers = ["Pointless!", "Ground beef!", "", "", ""]

#bot.joke
@client.event
async def on_message(message):
    if message.author != client.user:
        if message.content.startswith('bot.joke'):
            rand = random.randint(0,1)
            client.send_message(message.channel, jokes[rand])
            async def on_messge(message):
                if message.author != client.user:
                    if what in message.content:
                        await client.send_message(message.channel, answers[rand])
                        await client.send_message(message.channel, 'HAHAHAHA!!')

#My repo is at https://github.com/DaOnlyDominic/daonlydominic-bot
#It does have some extra code
#I host on Heroku

我要让用户说:“ bot.joke” 机器人讲出这个笑话,然后用户说:“什么?” 然后,机器人告诉答案。

1 个答案:

答案 0 :(得分:0)

我注意到您在on_message上有错字。

但是,我也建议您将pyjokes模块用于这个非常重要的应用程序。

import pyjokes
print(pyjokes.get_joke())