You can download this code by clicking the button below.
This code is now available for download.
This function generates a random greeting message based on the input message content.
Technology Stack : Discord.py, random
Code Type : Discord Bot Function
Code Difficulty : Intermediate
import discord
import random
def create_random_greeting(message_content):
# Create a greeting message based on the content of the message
greetings = ["Hello", "Hi", "Hey", "Greetings", "Hola"]
return f"{random.choice(greetings)} {message_content}!"
# JSON representation of the function details
json_data = {
"type": "Discord Bot Function",
"hard": "中级",
"explain": "这个函数根据传入的消息内容生成一个随机的问候语。",
"tench": "Discord.py, random",
"explain_en": "This function generates a random greeting message based on the input message content.",
"tench_en": "Discord.py, random"
}
# Example usage:
# bot = discord.Client()
# @bot.event
# async def on_message(message):
# if message.author == bot.user:
# return
# greeting = create_random_greeting(message.content)
# await message.channel.send(greeting)
# bot.run('your_token_here')