上下文
我正在制作一个discord.py(重写-v1.0+) bot,我用一些基本的sql和python创建了一个cog来创建一个聊天机器人,但是当'message‘事件发生时,wait_for方法完全忽略它。
我是Discord.py的新手,所以任何帮助都是非常感谢的!
迷你代码:
"""ai cog"""
import discord
from discord.ext import commands
import asyncio
class ai(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(aliases=['c','ch','cha'])
async def chat(self, ctx, *, message:str):
Bot = 'Hello!'
# I am guessing problem is here
def nobotspeakshere(message):
if message.author.bot == True:
return False
while True:
# try:
msg = await user.wait_for('message', check=nobotspeakshere)
# ^^^^^^^^^^
# The problem seems to be here.
# except asyncio.TimeoutError:
# await ctx.send('Bot: bye')
# break
you = msg.content
print(you)
if you.lower() in ["", "bye!", "bye"]:
return await ctx.send('Bot: ' + Bot)
await ctx.send('Bot: Bye!')
#some working sql
#sql gives bot = "something else"
def setup(bot):
bot.add_cog(ai(bot))预期产出
打印变量“you”并继续执行
输出
忽略在通道中输入的消息。
期望问题
nobotspeakshere函数不像预期的那样起作用。
发布于 2019-09-20 13:54:16
您的函数从不返回True,只返回False (如果作者是bot)或None (默认返回值)。由于None是一个虚假值,discord.py将其视为false。
最好的改变是总是返回与message.author.bot相反的内容
msg = await user.wait_for('message', check=lambda message: not message.author.bot) https://stackoverflow.com/questions/58025616
复制相似问题