문자열을 인수로 받아들이는 방법은 무엇입니까? (discord.py 재 작성)

Dec 17 2020

문자열을 인수로 받아들이는 discord.py 명령을 만들려고합니다. Discord 메시지에서 문자열을 인수로 받아들이는 방법 (부울과 정수를 수행하는 방법을 말할 수 있다면 도움이 될 것입니다)? 나는 그것에 최선을 다해 덕 푸를 시도했다.

수입품

os
discord
json
requests
python-dotenv
pymediawiki

예제 코드

#Existing bot

@bot.command()
async def combinestring(ctx):
#argument should be called arg

#process string
   

(필요하다면 더 추가해도 괜찮습니다.)

답변

1 ŁukaszKwieciński Dec 17 2020 at 16:28

말 그대로 명령 소개를 읽을 때 나타나는 첫 번째 것입니다. 여기에 링크가 있습니다.

또한 여기에 예가 있습니다.

@bot.command()
async def foo(ctx, arg):
    await ctx.send(arg)

# To invoke
# !foo hello
# >>> hello
JoaquimEsteves Dec 17 2020 at 15:41

Discord 봇에서 메시지를받는 것과 관련된 다른 질문을 살펴 보셨습니까?

  • https://stackoverflow.com/a/61851683/6595024
  • https://stackoverflow.com/a/49127887/6595024

편집 : 질문에 대한 업데이트가 주어진 업데이트 된 답변

iamthetrueyes Dec 20 2020 at 17:49

꽤 간단합니다 공백없이 논쟁을하고 싶다면,

@bot.command()
async def combinestring(ctx, arg: str):
    #your code

공백으로 논쟁을 벌이고 싶다면

@bot.command()
async def combinestring(ctx, *, arg):
    #your code

끝난.