【发布时间】:2018-12-02 22:55:46
【问题描述】:
我今天尝试制作一个基于 python discord.py 的机器人以获得一些乐趣,并且遵循一些随机教程并复制代码效果很好,一旦掌握了它,我就添加了一些新命令,但显然大多数命令随机停止工作,由于某种原因,现在只有最底层的命令实际上在不和谐中运行,任何想法为什么会这样? 代码:
import discord
from discord.ext import commands
description = 'Tutorial Bot'
bot_prefix = '!'
client = commands.Bot(description=description, command_prefix=bot_prefix)
list_of_strings = ['hello', 'hi']
@client.event
async def on_ready():
print('Connected')
@client.event
async def on_message(message):
if message.content.startswith('!what'):
await client.send_message(message.channel, 'Huh?')
@client.event
async def on_message(message):
if message.content in list_of_strings:
await client.send_message(message.channel, 'Hey there')
client.run('*set to code before attempting*')
我已经将 client.run 设置为最新的代码,但是每当我使用字符串命令的底部列表时它都可以正常工作,但是 !what 部分不起作用。我尝试扭转它们,但同样的问题仍然存在,无论它们处于哪个顺序,只有最底部的一个在工作。我可能在这里遗漏了一些明显的东西吗?
【问题讨论】:
-
我以前没用过这个,但大概第二个会覆盖第一个...
标签: python bots discord discord.py