因此,我目前正在处理一个softban命令,我希望用户获得每个dm发送一个新的inv链接。但它并没有向他们发送信息。这是我的密码。谢谢大家!
@client.command(pass_context=True)
async def softban(ctx, user: discord.User=None):
if user == None:
embed = discord.Embed(title=f"**Softban**",
description=f"Softban will ban but immediately unban the user and send them a new invite link!"
f"\nUsage: {prefix}softban <User>")
await ctx.send(embed=embed)
try:
inv = await ctx.author.guild.create_invite(max_uses=1)
await user.send(f"You got softbanned from {ctx.author.guild}\nJoin again with this link: {inv}")
except:
await ctx.send("User probably has their dms closed!")
await ctx.guild.ban(user)
await asyncio.sleep(0.1)
await ctx.guild.unban(user)
await ctx.send(f"{user.mention} got softbanned!")
print(f"{user} got softbanned from {ctx.guild.name}")
代码中存在某种逻辑错误。您必须在
try
语句中ban
和unban
用户。我也会考虑再次查看^ {CD4}},看看你需要什么。查看以下代码:
ctx.channel.create_invite
user
我们说它必须是discord.Member
可在此处找到相关文档:
相关问题 更多 >
编程相关推荐