【问题标题】:Nextcord.py scheduled guild events str doesn't have attribute valueNextcord.py 计划的公会事件 str 没有属性值
【发布时间】:2022-01-11 14:42:21
【问题描述】:

我正在尝试使用 nextcord.py/dpy 和 discord 官方事件制作一个不和谐事件机器人,但我遇到了 entity_type 问题,因为它给了我一个错误 type error str 没有属性值,我对此感到困惑

这是我的命令

@client.command(name='rp' ,help= 'creates an event')
async def rp(ctx, name=None, time =None, reason = None):
  #external = 
  channel = nextcord.utils.get(ctx.guild.channels, name = 'roleplay-sessions')
  await ctx.guild.create_scheduled_event(name=name, channel = channel, start_time = time, description = reason, entity_type = 'external')

任何帮助都会很棒,因为它已经 13 个小时了,我的头很痛,谢谢

【问题讨论】:

    标签: python discord.py nextcord


    【解决方案1】:

    nextcord doc

    你需要使用:

    entity_type = nextcord.ScheduledEventEntityType.external
    

    还有:

    • 频道必须是voice_channel
    • 所有参数都是必需的
    • start_time 需要在将来
    • 对于 start_time 和 end_time 使用 timezone.utc

    Type.external sn-p

    @client.command()
    async def rp(ctx):
        now = datetime.now(timezone.utc) + timedelta(seconds=10)
        tomorrow = now + timedelta(days=1)
        await ctx.guild.create_scheduled_event(
            name="roleplay-sessions",
            privacy_level = nextcord.ScheduledEventPrivacyLevel.guild_only, # optional
            metadata = nextcord.EntityMetadata(location='roleplay-sessions'),
            start_time = now,
            end_time = tomorrow,
            description = 'lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et.',
            entity_type = nextcord.ScheduledEventEntityType.external
            )
    

    Type.voice sn-p

    @client.command()
    async def rp(ctx):
        channel = ctx.guild.get_channel(int(CHANNEL_ID)) # voice_channel
        now = datetime.now(timezone.utc) + timedelta(seconds=10)
        await ctx.guild.create_scheduled_event(
            name="roleplay-sessions",
            channel = channel,
            privacy_level = nextcord.ScheduledEventPrivacyLevel.guild_only, # optional
            start_time = now,
            description = 'lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et.',
            entity_type = nextcord.ScheduledEventEntityType.voice
            )
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • @Flekay 如果我想有一个可自定义的开始时间,比如说我让用户说是今天下午 3 点而不是现在,我该怎么做
    • @TheRavenSeb 查看 datetime.strptime() docs.python.org/3/library/… 否则你必须编写自己的类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 2016-09-20
    • 2019-03-25
    • 2017-05-13
    相关资源
    最近更新 更多