【问题标题】:Discord Bot python 3.6 report commandDiscord Bot python 3.6 报告命令
【发布时间】:2020-08-11 17:57:45
【问题描述】:

我正在用 python 制作一个自定义的不和谐机器人。我正在尝试添加一个 !report 命令。 我很困惑,无法在任何地方找到答案。有人可以帮我做吗?

我希望任何用户都能做到!report @example reason. 并将其保存在 excel 或 sql3 等数据库中,或者最好保存在员工频道中。 我该怎么做?

我尝试过使用on_message()

【问题讨论】:

    标签: python-3.6 discord discord.py


    【解决方案1】:

    您可以使用on_message() 命令:

    @client.event
    async def on_message(message):
        if message.content.startswith("!report"):
            report_channel = client.get_channel(channel id)
            member = text.split(" ")[1]
            reason = ' '.join(text.split(" ")[1:])
            await report_channel.send(f"Member: {member}, Reason: {reason}")
    

    所以首先要查看该人是否使用带有 if 语句的“!report”命令。

    接下来,您通过获取消息的第二个单词来找到该成员。

    然后,您通过查看消息中的其余单词来找到原因。

    然后你将它发送到不和谐的预定义报告频道。

    【讨论】:

    • 我收到错误AttributeError: 'Message' object has no attribute 'startswith'
    • 你使用了小写的 m 吗?
    • 对不起,它的message.content.startswith() 我会改变答案。 message 是对象,content 是文本。
    • 很抱歉打扰你,但当我得到NameError: name 'text' is not defined
    • 把这两个都改成message.content 抱歉我写得很快,无法运行它
    猜你喜欢
    • 2019-03-07
    • 1970-01-01
    • 2018-10-21
    • 2021-03-01
    • 2018-07-08
    • 2021-04-11
    • 2018-07-07
    • 2021-02-17
    • 2018-03-04
    相关资源
    最近更新 更多