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

Discord.py 多整数参数问题:Spam命令转换错误求助

Fixing the "Converting to 'int' failed for parameter 'title'" Error in Your Discord.py Spam Command

Let's break down exactly what's happening here — that error is spelling out the issue clearly: you declared the title parameter as an int (integer), but when you run the command, you're passing in text for the title. Discord.py can’t turn a piece of text like "My Spam Header" into a number, so it throws that conversion failure error.

The Quick Fix

Change the type annotation for title from int to str (string) so Discord.py knows to treat it as text instead of trying to convert it to a number:

@bot.command()
async def spam(ctx, amount: int, title: str, *, message):
    # Your command logic here
    for _ in range(amount):
        # Example: Send a formatted message with title and content
        await ctx.send(f"**{title}**\n{message}")

Handling Titles With Spaces

If you want your title to include spaces (like "My Cool Spam Title"), users will need to wrap the title in quotes when running the command. For example:

!spam 5 "My Cool Spam Title" This is the spam message content

This tells Discord.py to treat everything inside the quotes as a single title parameter, and the rest of the input as the message content.

Extra Tips to Avoid Headaches

  • Limit the amount parameter: Add a check to prevent users from spamming hundreds of messages at once (which could get your bot banned). For example:
    if amount > 20:
        await ctx.send("Sorry, you can't spam more than 20 messages at once!")
        return
    
  • Add delays between sends: Discord has rate limits, so adding a small delay will keep your bot from getting blocked:
    import asyncio
    
    for _ in range(amount):
        await ctx.send(f"**{title}**\n{message}")
        await asyncio.sleep(1)  # Wait 1 second between messages
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 14:17:29