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
Python Check Multi-Level Dict Key Existence
How to Make Print() Accept the User Input in Same Line
How to Print a String Multiple Times
Convert Image Files to a CSV File
Truth Value of a Series Is Ambiguous. Use A.Empty, A.Bool(), A.Item(), A.Any() or A.All()
Stored Procedures With Sqlalchemy
Calculating Manhattan Distance in Python in an 8-Puzzle Game
How to Copy a File to a Remote Server in Python Using Scp or Ssh
Pyodbc Error Data Source Name Not Found and No Default Driver Specified Paradox
Python: Import Cx_Oracle Importerror: No Module Named Cx_Oracle Error Is Thown
Python Comparing List Values to Keys in List of Dicts
How to Merge Two Cnn That Are Trained Over Different Data Stream
Typeerror: Image Data Can Not Convert to Float
Pandas Get Frequency of Item Occurrences in a Column as Percentage
How to Display a Plot in Fullscreen
How to Share Data Between a Parent and Forked Child Process in Python