To loop a task in Discord.py using asyncio.sleep() and asyncio. Method 2: Using asyncio.sleep() and asyncio.create_task() ![]() That's it! This is one way to loop a task in Discord.py using a while loop. 3) Locate the specific user from your friend. 2) Select the Advanced tab from the left and toggle on Developer Mode. 1) Launch Discord and click the gear icon to access the User’s settings. Note that you will need to replace channel_id_here with the ID of the channel you want to send messages to, and your_token_here with your Discord bot token. If you simply want to get the Discord ID of someone who has already been your friend, follow the instruction below. We then create a task using _task() to run the my_background_task() coroutine in the background. Within the loop, we increment the counter by 1, send a message to the channel with the current counter value, and then wait for 60 seconds using asyncio.sleep(60).įinally, we define the on_ready() event handler that prints some information about the client when it is ready. Next, we create a while loop that runs indefinitely as long as the client is not closed. It should look like this on Android & for iOS: Obtaining Server IDs - Mobile App On Android press and hold the Server name above the channel list. Press those dots and you should see the last item on the drop-down menu: 'Copy ID'. We then set a counter variable to 0 and define a channel object that we want to send messages to. You should see three dots on the top-right. Within the my_background_task() coroutine, we first wait until the client is ready using client.wait_until_ready(). Second way to find out what email is linked to Discord: Through your email. We then create a Client object and define a coroutine called my_background_task(). First method to find out what email is linked to Discord: Through your account. ![]() In this example, we first import the discord and asyncio libraries. event async def on_ready ( ) : print ( 'Logged in as' ) print (client. sleep ( 60 ) # task runs every 60 seconds. send_message (channel, counter ) await asyncio. ![]() Object ( id = 'channel_id_here' ) while not client. Client ( ) async def my_background_task ( ) : await client.
0 Comments
Leave a Reply. |