有没有办法从
Untimeout
dms
获得用户?
我尝试使用此代码:
@bot.command()
async def untimeout(ctx, user: discord.Member, guild_id: int):
guild = bot.get_guild(guild_id)
if guild:
try:
await user.untimeout()
except Exception as e:
await ctx.reply(f"ERROR: {e}")
else:
await ctx.send("Guild not found.")
要从 Discord 中的 DM 中取消用户超时,请首先获取公会,然后从该公会中检索成员,最后取消用户超时。
import discord
from discord.ext import commands
@bot.command()
async def untimeout(ctx: commands.Context, user: discord.User, guild_id: int):
guild = bot.get_guild(guild_id) # 1. get the guild
if guild:
member = guild.get_member(user.id) # 2. get the member
if member:
await member.timeout(None) # 3. untimeout
await ctx.reply("The user has been untimed out")
else:
await ctx.reply("User not found")
else:
await ctx.reply("Guild not found")
要测试此命令,请输入以下命令:
untimeout <@user_id_here> guild_id_here
为了简化命令并使其更方便,我们可以替换两部分代码:
user_id
async def untimeout(ctx: commands.Context, user_id: int, guild_id: int) -> None:
member
member = guild.get_member(user_id)
通过这些更改,用户现在可以使用以下命令:
untimeout user_id_here guild_id_here