我正在尝试使机器人离开ID为Command!leave
的服务器。我收到错误'Bot' object has no attribute 'get_server'
这是我的剧本:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='!')
token = TOKEN HERE
@client.command()
async def leave(ctx, ID):
toleave = client.get_server(ID)
await client.leave_server(toleave)
print("Left Server")
client.run(token)
答案 0 :(得分:4)
自从discord.py 1.1起,get_server
已重命名为get_guild
,并且leave_server
已移至Guild.leave
。因此,您的代码应类似于:
toleave = client.get_guild(ID)
await toleave.leave()
答案 1 :(得分:0)
这应该有效
@commands.command()
async def leave(self, ctx, *, message=None ):
guild_id = message
guild = await self.client.get_guild(int(guild_id))
channel = guild.system_channel
await channel.send("Leaving this server due to misuse!")
await guild.leave()