阅读RPG机器人不和谐使用Python机器人



我试图制作一个简单的python机器人来读取RPG机器人,当发生组事件时,它会发送文本来召集所有人。我正在使用Replit,所以我想说最新的python 3.8.2

import requests
import discord
import time

client = discord.Client()
async def on_ready():
print('Logged in As {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
msg = message.content
if message.content.startswith('Event'):
time.sleep(2)
await message.channel.send("Event Starting @everyone")
if any(word in msg for word in ('event')):   
time.sleep(2)
await message.channel.send("@everyone Event time")

client.run(os.environ['token'])

如果不使用discord重写,请尝试使用它https://github.com/Rapptz/discord.py

使用代码的小示例:

import discord
from discord.ext import commands
import time
import os
bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())
bot.remove_command("help")
token = "token here"
@bot.event
async def on_ready():
print(f"We have logged in as {bot.user}")
@bot.event
async def on_message(msg):
await bot.process_commands(msg)
if msg.author == bot.user or msg.author.bot:
return
elif "event" in msg.content.lower(): #here we are lower all message content and try to finding "event" word in message.
time.sleep(2)
await msg.channel.send("Event Starting @everyone")
return
#if you want to use this as bot command, not as default text.
@bot.command(name="event")
async def event(msg):
time.sleep(2)
await msg.channel.send("Event Starting @everyone")
return

bot.run(token)

相关内容

  • 没有找到相关文章

最新更新