[英]Discord.py | I'm trying to make my bot unban with both Member Name and Member ID
My code(Inside a Cog):我的代码(在齿轮内):
import discord
import datetime
from discord.ext import commands
class unban(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
@commands.has_permissions(ban_members = True)
async def unban(self, ctx, id: int):
user = await self.client.fetch_user(id)
await ctx.guild.unban(user)
unban= discord.Embed(title=f'A moderation action has been performed!', description='', color=0x90fd05)
#unban.add_field(name='User Affected:', value=f'`{member.name}`', inline=True)
#unban.add_field(name='User ID:', value=f'`{member.id}`', inline=True)
unban.add_field(name='Moderator Name:', value=f'`{ctx.author}`', inline=True)
unban.add_field(name='Moderator ID:', value=f'`{ctx.author.id}`', inline=True)
unban.add_field(name='Action Performed:', value='`UnBan`', inline=True)
unban.set_author(name=f'{ctx.guild}', icon_url=ctx.guild.icon_url)
#unban.set_thumbnail(url=member.avatar_url)
unban.timestamp = datetime.datetime.utcnow()
await ctx.send(embed=unban)
def setup(client):
client.add_cog(unban(client))
I've made the command so I can unban people.我已经下达了命令,所以我可以解禁人们。 But I can only unban with their ID.但是我只能用他们的ID解禁。 I want it to unban with their Name too.我也希望它用他们的名字解禁。 So how could I do that?那我怎么能这样做呢?
I've also tried replacing the:我也尝试过更换:
async def unban(self, ctx, id: int):
with:和:
async def unban(self, ctx, member : discord.Member):
but nothing worked.但没有任何效果。 and I've tried using both:我已经尝试使用两者:
async def unban(self, ctx, member : discord.Member, id: int):
but still nothing worked...但仍然没有任何效果......
async def unban(self, ctx, member : discord.Member):
It will not work due to a banned member can only be represented by discord.User
or by an ID.由于被禁止的成员只能由discord.User
或 ID 表示,因此它不起作用。
async def unban(self, ctx, user_id : int):
user = await self.client.fetch_user(user_id)
await ctx.guild.unban(user)
This will only work with ID's so discord can locate the user in their database.这仅适用于 ID,因此 discord 可以在其数据库中找到用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.