【问题标题】:My say command keeps running into errors and i cant figure out how to do it help would be appricated我的说命令不断遇到错误,我不知道该怎么做
【发布时间】:2020-05-26 07:30:48
【问题描述】:

所以我试图做一个说命令,所以如果我的服务器不和谐开发团队的成员使用它,那么它会向公告频道发送一条消息。使用discord.py和python的重写,它根本不会发送消息或删除消息这是我的代码

@bot.command(pass_context=True) @commands.has_role('Manager') async def say(ctx, content): channel = ctx.guild.get_channel("714229744798925012") await channel.send(channel,content) await Message_delete(content) 我知道为什么会发生这种情况,它还说经理 cos 我在测试服务器上对其进行测试,然后才上线

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    您不能将文本作为参数传递给@bot.command 函数。一般你用这个:

    async def say(ctx, *args):
    

    args 是您消息的空格分隔子字符串的元组(又名单词;-))。例如

    !say Hello world
    

    将为您呈现

    args = ("Hello", "world")
    

    要将元组转换为字符串,只需使用:

    message = ""
    message = ' '.join(args)
    

    总共:

    @bot.command(pass_context=True)
    @commands.has_role('Manager')
    async def say(ctx, *args):
        message = ""
        message = ' '.join(args)
        channel = ctx.guild.get_channel("714229744798925012")
        await channel.send(channel, message)
    

    如果你以后想添加删除消息的命令,我建议存储它的 ID 以供以后使用。

    【讨论】:

    • “您不能将文本作为参数发送给@bot.command 函数”这是不正确的。你应该参考这部分文档:discordpy.readthedocs.io/en/latest/ext/commands/…
    • 我的意思是,你不能将它作为字符串传递。您提供的链接正是我上面描述的解决方案。
    • 可以使用async def say(ctx, *, content):,即命令调用后的完整字符串会存储在content
    猜你喜欢
    • 2013-04-25
    • 2020-09-29
    • 2016-09-02
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2014-02-28
    • 2022-01-08
    相关资源
    最近更新 更多