这是我的代码:
@client.command(pass_context=True)
async def banall(ctx):
await ctx.message.delete()
for user in list(ctx.guild.members):
try:
await ctx.guild.ban(user)
await ctx.send(f"{user.name} has been banned from {ctx.guild.name}")
except:
await ctx.send(f"{user.name} has FAILED to be banned from {ctx.guild.name}")
我正在尝试做到这一点,所以当有人说“ banall”时,它将禁止服务器中的所有成员。我发现已经找到了此命令,但是可以使用“!banall”,但是我想摆脱“!”,因此它就是“ banall”。有人知道我会怎么做吗?:D < / p>
答案 0 :(得分:1)
on_message()
。这可以通过删除方法装饰器(@client.command(pass_context=True)
)并将ctx
更改为消息来完成,因为on_message()
函数获得了message
对象。async def banall(message):
await message.delete()
for user in list(message.guild.members):
try:
await message.guild.ban(user)
await message.channel.send(f"{user.name} has been banned from {message.guild.name}")
except:
await ctx.send(f"{user.name} has FAILED to be banned from {ctx.guild.name}")
on_message()
中运行该功能。可以使用if语句来检查消息的内容是否为“ banall”。@client.event
async def on_message(message):
if message.content == "banall":
await banall(message)
答案 1 :(得分:0)
如果要剪切“!”在“!banall”中,您需要执行以下操作:
string = "!banall"
string2 = string.replace('!', '')