discord.py: wait_for() 方法的检查参数阻止执行
discord.py: wait_for() method's check argument preventing execution
上下文
我正在制作一个 discord.py(rewrite-v1.0+) bot,我用一些基本的 sql 和 [=50 创建了一个 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
功能未按预期运行。
你的函数永远不会 returns True
,只有 False
(如果作者是机器人)或 None
(默认 return 值) .由于 None
是一个假值,discord.py 将其视为假值。
最好的改变总是return与message.author.bot
相反
msg = await user.wait_for('message', check=lambda message: not message.author.bot)
上下文
我正在制作一个 discord.py(rewrite-v1.0+) bot,我用一些基本的 sql 和 [=50 创建了一个 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
功能未按预期运行。
你的函数永远不会 returns True
,只有 False
(如果作者是机器人)或 None
(默认 return 值) .由于 None
是一个假值,discord.py 将其视为假值。
最好的改变总是return与message.author.bot
相反
msg = await user.wait_for('message', check=lambda message: not message.author.bot)