You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discum中SlashCommander触发列表索引越界错误求助

Discum代码SlashCommander列表索引越界问题求助

我现在遇到了Discum代码的问题:第22行的SlashCommander部分触发了列表索引越界错误。我已经查阅过slash.py的源码但没找到解决办法,尝试过多种修复方案都失败了,现在多数情况下还会出现KeyError,实在搞不懂问题出在哪。

我用的是2023年末版本的Discum,先后两次降级Discum、更换Python版本都没能解决问题。一开始以为是embeds索引的问题,但显然不是。

附上完整代码:

import discum 
from discum.utils.slash import SlashCommander
from discum.utils.button import Buttoner
import time
import random
from threading import Lock

bot = discum.Client(token='YOUR_TOKEN_HERE', log=False)

guildID = "YOUR_GUILD_ID_HERE"
channelID = "YOUR_CHANNEL_ID_HERE"
botID = "706183309943767112" # Camelot's userid

lock = Lock()

def send_command(resp):
    if resp.event.guild_application_commands_updated:
        bot.gateway.removeCommand(send_command)
        slashCmds = resp.parsed.auto()['application_commands']
        s = SlashCommander(slashCmds, application_id=botID)
        temp = s.get(['dungeon'], inputs={"floor":"40"}) # Change this number to change the floor to automate
        bot.triggerSlashCommand(botID, channelID, guildID, data=temp)
        print("attempting to summon mob")

@bot.gateway.command
def kill(resp):
    lock.acquire()

    if resp.event.ready_supplemental:
        bot.gateway.request.searchSlashCommands(guild_id=guildID, limit=50)
        print("ready")

    if resp.event.message or resp.event.message_updated:
        data = resp.parsed.auto()
        try:
            if data.get("webhook_id") == botID and data["interaction"]["user"]["id"] == bot.gateway.session.user["id"]:
                embeds = data["embeds"]
                if len(embeds) == 0:
                    print(data.get("content"))

                    if "to enter the code" in data.get("content"):
                        print("captcha has appeared")
                        input("press enter to continue...") # You could automatically solve the captcha, but you'd have to modify the code quite a lot
                        bot.gateway.close()

                    elif "You already have a run in progress" in data.get("content"):
                        print("we didn't kill last, sleepy time...")
                        time.sleep(60)
                        bot.gateway.close()

                    elif len(data.get("content")) > 0:
                        print("unknown message, closing down...")
                        bot.gateway.close()
                else:
                    if "Dungeon Floor" in embeds[0].get("title") and not "won" in embeds[0].get("description"):
                        buttons = Buttoner(data["components"])
                        
                        # ATK, DEF, ABILITY, SKILL, SKIP
                        combo = ['ATK','ATK', 'ATK', 'ATK', 'ATK'] # The button order to click
                        previous_cmd = None

                        for cmd in combo:
                            time.sleep(int(random.uniform(3,7))) # The delay before clicking any buttons
                            bot.click(data["webhook_id"],
                                    channelID=data["channel_id"],
                                    guildID=data.get("guild_id"),
                                    messageID=data["id"],
                                    messageFlags=data["flags"],
                                    data=buttons.getButton(customID=cmd),
                                    sessionID=bot.gateway.session_id)
                            
                            # this will automatically send an attack after you've cast "skill" (class skill), 
                            # feel free to modify to your needs if you don't need this.
                            if cmd == 'SKILL' and previous_cmd != 'SKILL':
                                time.sleep(2)
                                bot.click(data["webhook_id"],
                                    channelID=data["channel_id"],
                                    guildID=data.get("guild_id"),
                                    messageID=data["id"],
                                    messageFlags=data["flags"],
                                    data=buttons.getButton(customID='ATK'),
                                    sessionID=bot.gateway.session_id)
                            previous_cmd = cmd
                        bot.gateway.close()
        except: pass
    lock.release()

bot.gateway.command({"function":send_command, "params":{}})              
bot.gateway.run()

报错信息:

> ready Exception ignored in thread started by: <bound method
> GatewayServer._response_loop of <discum.gateway.gateway.GatewayServer
> object at 0x000001C8E52AD890>> Traceback (most recent call last):  
> File
> "C:\Users\ophelia\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\gateway.py",
> line 303, in _response_loop
>     function(resp, **params)   File "bot.py", line 22, in send_command
>     s = SlashCommander(slashCmds)   File "C:\Users\ophelia\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\utils\slash.py",
> line 9, in __init__
>     elif type(commands) in (list, tuple) and isinstance(commands[0], dict): IndexError: list index out of range

希望有人能提供解决思路。

内容的提问来源于stack exchange,提问作者Ophelia Son

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 17:37:08