Python 3.x 如何发出命令使我的bot离开特定服务器?
我想使用类似于Python 3.x 如何发出命令使我的bot离开特定服务器?,python-3.x,discord.py-rewrite,Python 3.x,Discord.py Rewrite,我想使用类似于-svleave的命令以及服务器的名称或id,然后使用bot离开该服务器。我在谷歌上搜索了如何做,但我只得到了这篇文章,它没有告诉我如何将它作为命令实现,比如:@client.command(),但我没有看到如何将它作为命令添加 from discord.ext import commands import discord.utils client = commands.Bot(command_prefix = "-") @client.event asyn
-svleave
的命令以及服务器的名称或id,然后使用bot离开该服务器。我在谷歌上搜索了如何做,但我只得到了这篇文章,它没有告诉我如何将它作为命令实现,比如:@client.command()
,但我没有看到如何将它作为命令添加
from discord.ext import commands
import discord.utils
client = commands.Bot(command_prefix = "-")
@client.event
async def on_ready():
print('Ahri is Ready!')
await client.change_presence(status=discord.Status.online, activity=discord.Game("cu pizda lui ma-ta"))
@client.command()
async def ping(ctx):
await ctx.send(f'Ping: {round(client.latency * 1000)}')
################################################################
# ADMIN #
################################################################
@client.command(pass_context=True) # Send Message As Bot
@commands.has_permissions(administrator=True)
async def sudo(ctx, *, message):
await ctx.message.delete()
await ctx.send(message)
@client.command() # Clears Messages
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount=5):
await ctx.channel.purge(limit=amount)
@client.command() # Kicks Members
@commands.has_permissions(kick_members=True)
async def kick(ctx, member : discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.send(f"Kicked {member.mention}")
@client.command() # Bans Members
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
await member.ban(reason=reason)
await ctx.send(f"Banned {member.mention}")
@client.command() # Unbans Members
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member):
banned_users= await ctx.guild.bans()
member_name, member_discriminator = member.split('#')
for ban_entry in banned_users:
user = ban_entry.user
if (user.name, user.discriminator) == (member_name, member_discriminator):
await ctx.guild.unban(user)
await ctx.send(f"Unbanned {user.mention}")
return
################################################################
# ROLES #
################################################################
role = "Newcomer"
@client.event
async def on_member_join(member):
rank = discord.utils.get(member.guild.roles, name = role)
await member.add_roles(rank)
@client.command()
@commands.is_owner()
async def leaveguild(self, ctx, *, guild: discord.Guild):
await guild.leave()
await ctx.send(f"I've left {guild.name}!")
client.run("")
下面的代码允许您输入帮会的名称或ID以离开帮会,并确保您(机器人的所有者)是运行该命令的人 你可以读更多
导入不一致
从discord.ext导入命令
@client.command()
@commands.is_owner()
异步def leaveguild(ctx,*,guild:discord.guild):
等待公会离开
等待ctx.send(f“我已经离开了{guild.name}!”)
欢迎来到stackoverflow@SE。可怜我们这些非母语人士吧:试着明确无误地表达出痛苦的想法。不要使用非普通/常见的缩写、首字母缩略词或标记,如。我遇到以下错误:discord.ext.commands.errors.MissingRequiredArgument:guild是缺少的必需参数。是的,您需要为guild参数提供输入。因此,就像[p]leaveguild[guildname | guildid]
[p]leaveguild MyGuild是的,我键入-leaveguild 719568406495625238,它不起作用,如果我尝试键入名称(它之间有空格),它会说raise BAD参数({}转换为“{}”失败)。格式(名称,param.name))从exc discord.ext.commands.errors.BadArgument:参数“Guild”转换为“Guild”失败。我已经编辑了我的答案,允许服务器名称带有空格,虽然ID应该可以工作,但ID会出现什么错误?(请注意,编辑是ctx和guild之间的星号“*”).discord.ext.commands.errors.MissingRequiredArgument:guild是缺少的必需参数。还是这个,我输入了身份证