Reputation: 114
I am using python to make my bot generate an instant invite. However I have trouble finding and creating the instant invite. Here is my code:
from progress.bar import Bar # Only to show a loading bar, all imports are successful.
print("Loading...")
imports = [
'import os',
'import sys',
'import asyncio',
'import discord',
'import random',
'import functools',
'import time as tm',
'from discord.ext import commands',
'from discord.ext.commands import when_mentioned'
]
bar = Bar('', max=len(imports))
for i in range(0, len(imports)):
exec(str(imports[i]))
bar.next()
bar.finish()
BOT_PREFIX = "!"
BOT_TOKEN = 'token'
OWNER_ID = int("owner's user id for support")
class Stuff(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def create_invite(self, ctx):
"""- Create instant invite"""
link = await discord.abc.GuildChannel.create_invite(self, max_age='300')
await ctx.send("Here is an instant invite to your server: "+link)
When the command is run in discord, I get this error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Stuff' object has no attribute '_state'
How can I properly generate an instant invite?
Upvotes: 2
Views: 17437
Reputation: 1
Here is an example; format it as you like:
@client.command(pass_context=True)
async def invite(ctx):
#Creating an invite link
link = await ctx.channel.create_invite(xkcd=True, max_age = 0, max_uses = 0)
#max_age = 0 The invite link will never exipre.
#max_uses = 0 Infinite users can join throught the link.
#-----------------------------------------------------#
#-------Embed Time-----#
em = discord.Embed(title=f"Join The {ctx.guild.name} Discord Server Now!", url=link, description=f"**{ctx.guild.member_count} Members** [**JOIN**]({link})\n\n**Invite link for {ctx.channel.mention} is created.**\nNumber of uses: **Infinite**\nLink Expiry Time: **Never**", color=0x303037)
#Embed Footer
em.set_footer(text=f"Made by </iFreakuš„YT>2.0#0908")
#Embed Thumbnail Image
em.set_thumbnail(url=ctx.guild.icon_url)
#Embed Author
em.set_author(name="INSTANT SERVER INVITE")
#-----------------------------------------#
await ctx.send(f"> {link}", embed=em)
OUTPUT:
Upvotes: 0
Reputation: 191
Try using discord.TextChannel.create_invite()
Like so,
@commands.command()
async def create_invite(self, ctx):
"""Create instant invite"""
link = await ctx.channel.create_invite(max_age = 300)
await ctx.send("Here is an instant invite to your server: " + link)
Upvotes: 2