Discord Bot ctx захватывает только первое слово - PullRequest
1 голос
/ 05 мая 2020
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, поэтому, если я набираю? Idea, это отличная идея, записывается только «this». бот должен написать «это отличная идея». Я никогда не писал бота раньше и не могу понять, как это исправить.

1 Ответ

0 голосов
/ 06 мая 2020

Есть два способа go получить весь контент.

Это даст строку того, что они говорят. Например, ?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
...