TOKEN_USER1 = 'YOUR_USER1_TOKEN_HERE' # Replace with User 1's token
TOKEN_USER2 = 'YOUR_USER2_TOKEN_HERE' # Replace with User 2's token
CHANNEL_ID = 123456789012345678 # Replace with your channel ID
SCRIPT_FILE = 'script.txt' # Path to the script file
Delay between messages (in seconds)
DELAY = 2
Create Discord clients for the two users using discord.py-self
user1 = discord.Client()
user2 = discord.Client()
Load the conversation from the script file
def load_conversation():
"""Load and parse the conversation from the script file."""
conversation = []
try:
with open(SCRIPT_FILE, 'r') as file:
for line in file:
Split each line into user and message based on the first space
parts = line.strip().split(' ', 1)
if len(parts) == 2:
user, message = parts
conversation.append((user, message))
except Exception as e:
print(f"Error loading script: {e}")
return conversation
Message handling logic
async def handle_conversation(channel):
conversation = load_conversation()
if not conversation:
print("No valid conversation found.")
return
last_msg_user1 = None
last_msg_user2 = None
for speaker, message in conversation:
try:
if speaker == "user1":
# If the speaker is user1, send their message
print(f"User1 is sending: {message}") # Debugging print
if last_msg_user2:
# User1 replies to User2's last message and mentions User2
last_msg_user1 = await last_msg_user2.reply(content=message, mention_author=True)
else:
# First message sent directly by User1
last_msg_user1 = await channel.send(message)
await asyncio.sleep(DELAY) # Wait before User2 replies
elif speaker == "user2":
# If the speaker is user2, send their message
print(f"User2 is sending: {message}") # Debugging print
if last_msg_user1:
# User2 replies to User1's last message and mentions User1
last_msg_user2 = await last_msg_user1.reply(content=message, mention_author=True)
else:
# First message sent directly by User2
last_msg_user2 = await channel.send(message)
await asyncio.sleep(DELAY) # Wait before User1 replies
except Exception as e:
print(f"Error during message sending: {e}")
User1 on_ready event: Starts the conversation
@user1.event
async def on_ready():
print(f"User1 logged in as {user1.user}")
channel = await user1.fetch_channel(CHANNEL_ID)
if channel:
await handle_conversation(channel)
else:
print(f"Channel with ID {CHANNEL_ID} not found.")
User2 on_ready event: Starts the conversation when User2 is ready
@user2.event
async def on_ready():
print(f"User2 logged in as {user2.user}")
channel = await user2.fetch_channel(CHANNEL_ID)
if channel:
await handle_conversation(channel)
else:
print(f"Channel with ID {CHANNEL_ID} not found.")
Run both clients simultaneously
async def main():
try:
await asyncio.gather(user1.start(TOKEN_USER1), user2.start(TOKEN_USER2))
except Exception as e:
print(f"Error running the clients: {e}")
import discord import asyncio
Configuration: User tokens and channel ID
TOKEN_USER1 = 'YOUR_USER1_TOKEN_HERE' # Replace with User 1's token TOKEN_USER2 = 'YOUR_USER2_TOKEN_HERE' # Replace with User 2's token CHANNEL_ID = 123456789012345678 # Replace with your channel ID SCRIPT_FILE = 'script.txt' # Path to the script file
Delay between messages (in seconds)
DELAY = 2
Create Discord clients for the two users using discord.py-self
user1 = discord.Client() user2 = discord.Client()
Load the conversation from the script file
def load_conversation(): """Load and parse the conversation from the script file.""" conversation = [] try: with open(SCRIPT_FILE, 'r') as file: for line in file:
Split each line into user and message based on the first space
Message handling logic
async def handle_conversation(channel): conversation = load_conversation() if not conversation: print("No valid conversation found.") return
User1 on_ready event: Starts the conversation
@user1.event async def on_ready(): print(f"User1 logged in as {user1.user}") channel = await user1.fetch_channel(CHANNEL_ID) if channel: await handle_conversation(channel) else: print(f"Channel with ID {CHANNEL_ID} not found.")
User2 on_ready event: Starts the conversation when User2 is ready
@user2.event async def on_ready(): print(f"User2 logged in as {user2.user}") channel = await user2.fetch_channel(CHANNEL_ID) if channel: await handle_conversation(channel) else: print(f"Channel with ID {CHANNEL_ID} not found.")
Run both clients simultaneously
async def main(): try: await asyncio.gather(user1.start(TOKEN_USER1), user2.start(TOKEN_USER2)) except Exception as e: print(f"Error running the clients: {e}")
if name == "main": asyncio.run(main())