Создание мгновенного приглашения с использованием перезаписи discord.py, кажется, не может сделать это без ошибок - PullRequest
1 голос
/ 04 июля 2019

Я использую python, чтобы мой бот генерировал мгновенное приглашение. Однако у меня проблемы с поиском и созданием мгновенного приглашения. Вот мой код:

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)

Когда команда выполняется в разногласии, я получаю эту ошибку:

discord.ext.commands.errors.CommandInvokeError: Команда вызвала исключение: AttributeError: У объекта 'Stuff' нет атрибута '_state'

Как правильно создать мгновенное приглашение?

1 Ответ

0 голосов
/ 07 июля 2019

Попробуйте использовать discord.TextChannel.create_invite ()

Вот так,

@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)
...