Advertisement
Guest User

codelink

a guest
Dec 14th, 2022
2,002
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | Source Code | 0 0
  1. #main.py
  2. import discord
  3. from keep_alive import keep_alive
  4. from discord.ext import commands
  5. import os
  6. import openai
  7.  
  8. #make sure you have import all the above
  9.  
  10. bot = commands.Bot(
  11.   command_prefix='?', #any prefix you want
  12.   case_insensitive=False,
  13.   description=None,
  14.   intents=discord.Intents.all(), #enable intents in discord developer portal
  15.   help_command=None
  16. )
  17.  
  18. @bot.command()
  19. async def test(ctx,*,arg): # * is used to make sure your complete arguement is used rather than first word
  20.  
  21.   response = openai.Completion.create(
  22.     api_key = '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', #put your own api key here, mine doesnt work i deleted mine 🤣
  23.     model="text-davinci-003",
  24.     prompt=f"Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: How many pounds are in a kilogram?\nMarv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\nYou: What does HTML stand for?\nMarv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\nYou: When did the first airplane fly?\nMarv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away.\nYou: What is the meaning of life?\nMarv: I’m not sure. I’ll ask my friend Google.\nYou:{arg}\nMarv:",
  25.     temperature=0.5,
  26.     max_tokens=60,
  27.     top_p=0.3,
  28.     frequency_penalty=0.5,
  29.     presence_penalty=0.0
  30.   )
  31.   await ctx.channel.send(response)
  32.  
  33. @bot.event
  34. async def on_ready():
  35.   await bot.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.listening, name=f"Hi"))
  36.   print(f"Logged in as {bot.user.name}")
  37.  
  38. keep_alive()
  39.  
  40.  
  41. bot.run(os.environ['BOT KEY']) #create a secret token named BOT KEY and paste ur token
  42.  
  43. ################################
  44.  
  45. #keep_alive.py
  46. from flask import Flask
  47. from threading import Thread
  48.  
  49. app = Flask('')
  50.  
  51. @app.route('/')
  52. def home():
  53.     return "Hello. I am alive!"
  54.  
  55. def run():
  56.   app.run(host='0.0.0.0',port=8080)
  57.  
  58. def keep_alive():
  59.     t = Thread(target=run)
  60.     t.start()
  61.  
Tags: discord.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement