2017-09-11 10 views
1

저는 Python을 사용하고 있습니다. 여기 Discord Bot의 명령어 쿨 다운을 코딩하는 방법을 찾고 있습니다.

은 샘플 명령입니다 : 명령 'enablesentience이'트리거

@client.command(pass_context=True) 
async def enablesentience(ctx): 
    await client.say(":desktop: | User does not have sufficient permissions.") 

, 봇은 채팅 말한다 :

: 바탕 화면 : | 사용자에게 충분한 권한이 없습니다.

내가 찾고있는 것은이 명령에 재사용 대기 시간을 추가하는 방법으로 사람은 몇 초마다 한 번만 명령을 사용할 수 있습니다. 쿨 다운이 활성화 된 상태에서 명령을 시도하면 채팅에서 남은 쿨 다운 시간을 말할 수 있습니다.

이 나는 ​​시도했다 :

@client.command(pass_context=True) 
@commands.cooldown(1, 30, commands.server.user) 
async def enablesentience(ctx): 
    await client.say(":desktop: | User does not have sufficient permissions.") 

만했다

async def cooldown(1, 5, type=server.default) 

@client.command(pass_context=True) 
async def enablesentience(ctx): 
    await client.say(":desktop: | User does not have sufficient permissions.") 

은 각각 및 구문 오류 " '명령'객체는 '쿨 다운'에는 속성이 없습니다."

도움을 주시면 감사하겠습니다. 미리 감사드립니다.

답변

0

첫 번째 시도는 거의 옳았다 - 당신과 같이 대신 "commands.server.user"의하는 BucketType 사용 지정해야합니다

@commands.cooldown(1, 30, commands.BucketType.user) 

는 당신이 선택할 수있는 여러 버킷이 있습니다. 모두 소스 코드 here. (default은 글로벌을 의미합니다.)

+0

나는 당신이 무슨 뜻인지 모르겠다. "class BucketType (enum.Enum) :"을 추가해도 "enum"을 가져 오지 못하거나 BucketType 변수를 바꾸거나 BucketType을 사용하지 않았습니다. –