Discord Bot ctx仅捕获第一个单词

问题描述 投票:1回答:1
from discord.ext import commands
import random

description = '''An example bot to showcase the discord.ext.commands extension
module.

There are a number of utility commands being showcased here.'''
bot = commands.Bot(command_prefix='?', description=description)

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')




#here i need the help

@bot.command()
async def idea(ctx, content):
    """Repeats a message multiple times."""
    await ctx.send(content)
    f= open("supersmartidea.txt","a")
    f.write("¦" + content + "\n")

机器人只保护第一个输入为ctx的单词,因此如果我输入思想是一个好主意,只有“ this”被记录下来。机器人应该写下“这是个好主意”我以前从未编写过机器人程序,也无法弄清楚如何修复它。

python bots discord ctx
1个回答
0
投票

有两种方法可以获取全部内容。

这将给出他们所说的一串话。例如,?idea A good idea将返回:A good idea

@bot.command()
async def idea(ctx, *, content):
    #code

这将返回每个单词的元组。例如:?idea A good idea将返回:('A', 'good', 'idea')然后可以通过执行content = ' '.join(content)

将其转换为字符串。
@bot.command()
async def idea(ctx, *content):
    #code
© www.soinside.com 2019 - 2024. All rights reserved.