I am making a discord bot in discord.py, py-cord, and I was wondering if it's possible to have the bot generate a discord invite for a server and send it to you and how to do it?
Is it possible? And if so how do I do it?
I have figured it out thx for the help.
@client.command()
async def getinv(ctx):
invites = []
for guild in client.guilds:
for c in guild.text_channels:
# make sure the bot can actually create an invite
if c.permissions_for(guild.me).create_instant_invite:
invite = await c.create_invite()
invites.append(invite)
await ctx.send(invite)
break
A slightly improved version of the previous guys code
@client.event
async def on_ready():
for guild in client.guilds:
discord_guild = client.get_guild(int(guild.id))
link = await discord_guild.text_channels[0].create_invite()
print(link)
I've wanted to do the same thing, and I put together this script that prints invites to every server the bot is in.
from discord.utils import get
import discord
import asyncio
client = discord.Client()
TOKEN = "token here"
@client.event
async def on_ready():
print('Bot is up and running.')
print(f'Logged in as {client.user}')
@client.event
async def on_message(message, *ctx):
for guild in client.guilds:
discord_guild = client.get_guild(int(guild.id))
link = await discord_guild.text_channels[0].create_invite()
print(link)
asyncio.sleep(750)
client.run(TOKEN)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.