Creating instant invite using discord.py rewrite, can't seem to do so without errors
12,594
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)
![SUPER MECH M500](https://lh5.googleusercontent.com/-LSUwtmDDVJk/AAAAAAAAAAI/AAAAAAAADL4/0eg07slgYBw/photo.jpg?sz=256)
Author by
SUPER MECH M500
Updated on June 04, 2022Comments
-
SUPER MECH M500 about 2 years
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?