gpt4 book ai didi

python - 使用discord.py重写创建即时邀请,似乎无法没有错误

转载 作者:太空宇宙 更新时间:2023-11-03 20:40:32 36 4
gpt4 key购买 nike

我正在使用 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: Command raised an exception: AttributeError: 'Stuff' object has no attribute '_state'

如何正确生成即时邀请?

最佳答案

尝试使用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)

关于python - 使用discord.py重写创建即时邀请,似乎无法没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56890485/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com