How to Make a Discord Bot Leave a Server from a Command in Another Server

How to make a discord bot leave a server from a command in another server?

As client.leave_server() takes a Server as input, you will need to get that server first. Assuming you want to have a command that leaves a server based on the id that is given, this should do the trick:

toleave = client.get_server("id")
await client.leave_server(toleave)

where id is the ID of the server to leave.

How do i make a command that make my bot leave from the server (discord.py)

discord.Guild is a class not an instance (here's an explanation on what's the difference). You need to get the instance from somewhere, the easiest way would be with ctx.guild, (the bot will leave the guild where the command was invoked). The rest of the code was correct.

@bot.command()
async def leave(ctx):
await ctx.send("I am leaving this guild!")
await ctx.guild.leave()

Trying to make a bot leave a server by command

Since, discord.py 1.1, get_server has been renamed to get_guild, and leave_server has been moved to Guild.leave. So, your code would look something like:

toleave = client.get_guild(ID)
await toleave.leave()

How to make discord bot leave server just after joining

You can have the bot leave the server immediately after it joins by using the on_server_join event.

@client.event
async def on_server_join(server):
if server.id == "id":
await client.leave_server(server)

Trouble making a command to force bot to leave a server. (Discord,js)

The error message tells you all you need to know. You attempt to use a function called get_server(), but this function does not exist ergo you cannot use it.

A discord server in Discord.js is referred to as a Guild so to get your guild you can just call const guild = client.guilds.cache.fetch(guildid) and to leave it all you have to do is call guild.leave().

As a separate issue, a comparison in an if statement is made with 2 equal signs == not 1 as you did in your if (message.author.id = botowner) line.



Related Topics



Leave a reply



Submit