ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   Python (https://forum.antichat.xyz/forumdisplay.php?f=205)
-   -   дискорд стоп функция (https://forum.antichat.xyz/showthread.php?t=1475809)

TopCarl 30.04.2023 21:29

написал небольшого бота в дискорде чтобы флудил чат с активацией на команду, но хотелось бы узнать как останавливать это тоже с помощью команды

1:





Код:

@client.command()
async def popka(ctx):
  for i in range(2000000):
    guild = ctx.message.guild
    await ctx.channel.send("flood text")


VRush 30.04.2023 21:45

делаешь команду /stop:

stop = True

Python:





Код:

@client.command
(
)
async
def
popka
(
ctx
)
:
for
i
in
range
(
2000000
)
:
if
stop
:
wait ctx
.
channel
.
send
(
"flood stoped"
)
return
guild
=
ctx
.
message
.
guild
await
ctx
.
channel
.
send
(
"flood text"
)


TopCarl 30.04.2023 22:02

Цитата:

Сообщение от VRush

делаешь команду /stop:
stop = True

Python:





Код:

@client.command
(
)
async
def
popka
(
ctx
)
:
for
i
in
range
(
2000000
)
:
if
stop
:
wait ctx
.
channel
.
send
(
"flood stoped"
)
return
guild
=
ctx
.
message
.
guild
await
ctx
.
channel
.
send
(
"flood text"
)



немного не понял зачем мне два раза flood text

chromiusj 30.04.2023 22:06

Python:





Код:

is_flooding
=
False
@client.command
(
)
async
def
popka
(
ctx
)
:
global
is_flooding
    is_flooding
=
True
while
is_flooding
:
guild
=
ctx
.
message
.
guild
await
ctx
.
channel
.
send
(
"flood text"
)
@client.command
(
)
async
def
stop
(
ctx
)
:
global
is_flooding
    is_flooding
=
False



где нибудь объявляешь переменную флуда да и все


Время: 13:59