我有一些代码可用于生成check函数
wait_for。以下是我用来等待消息的方法
from collections.abc import Sequencedef make_sequence(seq): if seq is None: return () if isinstance(seq, Sequence) and not isinstance(seq, str): return seq else: return (seq,)def message_check(channel=None, author=None, content=None, ignore_bot=True, lower=True): channel = make_sequence(channel) author = make_sequence(author) content = make_sequence(content) if lower: content = tuple(c.lower() for c in content) def check(message): if ignore_bot and message.author.bot: return False if channel and message.channel not in channel: return False if author and message.author not in author: return False actual_content = message.content.lower() if lower else message.content if content and actual_content not in content: return False return True return check
然后,您可以轻松地将想要接收的消息的要求传递给
wait_for
check = message_check(author=ctx.author, channel=ctx.channel, content=('y', 'yes'))msg = await self.bot.wait_for("message", timeout=20.0, check=check)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)