【发布时间】:2021-05-22 14:07:08
【问题描述】:
我正在尝试从 discord 中获取消息并将消息放入名为 strlst 的列表中,但到目前为止,它并未将消息放入 strlst 并且终端中没有错误。因为我同时使用了@bot.event 和@bot.command(),所以我放了一个进程命令(idk 那是什么)。这里是:
import discord
from discord.ext import commands
@bot.event
async def on_message(ctx):
await bot.process_commands(ctx)
if ctx.content == ".add ":
ctx = ctx.content.lower()
newctx = ctx[4:]
strlist.append(newctx)
strlist = ["!cb","hello","no thank you", "you pass the butter"]
@bot.command(name="bb")
async def bb(ctx):
await ctx.send(f"WHAT DO YOU WANT ?")
# This will make sure that the response will only
be registered if the following
# conditions are met:
def check(msg):
return msg.author == ctx.author and
msg.channel == ctx.channel and \
msg.content.lower() in strlist
msg = await bot.wait_for("message", check=check)
if msg.content == '!cb':
await ctx.send("GOING DOWN . . .")
else:
await ctx.send("OK , COOL STORY . . .")
@bot.command(name="lst", help = "List of responses it will reply to", brief = f"The current responses available are:\n {strlist}\nNOTE:!cb cancels the bot")
async def current_lst(msg):
await msg.send("To add to the list, simply type .add [your message]")
这是有效的部分:
用户:!bb
机器人:你想要什么?
用户:你放弃了
Bot:好的,很酷的故事。 . .
用户:!bb
机器人:你想要什么?
用户:!cb
机器人:正在下降。 . .
我希望 .add 的部分像这样工作:
用户:.add 我有一个很酷的故事(机器人将它添加到 strlst)
用户:!bb
机器人:你想要什么?
用户:我有一个很酷的故事
机器人:很酷的故事兄弟。 . .
要点:我想将用户的消息添加到列表中。如果有其他方法可以做到这一点,我们将不胜感激。
【问题讨论】:
标签: python python-3.x discord discord.py