我的say命令不断出现错误,我无法弄清楚如何做到这一点。

问题描述 投票:0回答:1

因此,我试图执行一个使它发出声音的命令,因此如果我的服务器不和谐开发团队的成员使用它,那么它将向公告频道发送消息。它不会使用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)idk为什么会发生这种情况,还说经理cos im在上线之前在测试服务器上对其进行了测试

python discord.py
1个回答
0
投票

您不能传递文本作为参数发送给@ bot.command函数。通常,U使用此:

async def say(ctx, *args):

args是您的消息的各个子字符串(又称单词;-)的元组。例如

!say Hello world

将为您提供

args = ("Hello", "world")

只需使用以下命令即可将元组int转换为字符串:

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供以后使用。

© www.soinside.com 2019 - 2024. All rights reserved.