【发布时间】:2022-01-17 04:35:14
【问题描述】:
所以在这段代码中我使用了 replits 数据库扩展 Channel_IDS 是频道 ID 列表
from discord.ext import commands
from replit import db
import asyncio
bot = commands.Bot(command_prefix = ">>>")
Channel_IDS = []
db["Channels"]
Channel_IDS = db["Channels"]
@bot.event
async def on_ready():
print("logged in as "+str(bot.user))
YES = ["Yes","yes","YES"]
NO = ["No","no","NO"]
@bot.event
async def on_guild_channel_create(channel):
#channel = discord.utils.get(channel.guild.channels, name='channel name')
if channel.name == "global-chat":
id = channel.id
Channel_IDS.append(id)
await channel.send("successfully set <#"+str(id)+"> as global chat")
id = channel.id
print (Channel_IDS)
@bot.event
async def on_guild_channel_delete(channel):
if channel.id in Channel_IDS:
Channel_IDS.remove(channel.id)
print(Channel_IDS)
@bot.event
async def on_message(message):
if message.author == bot.user:
return
print("bot msg")
else:
if message.channel.id in Channel_IDS:
print("message received"+str(message.content))
for chann in Channel_IDS:
if chann == message.channel.id:
break
chenl = bot.get_channel(chann)
await chenl.send("**"+str(message.author)+"** :globe_with_meridians: " + str(message.content))
print("message sent" +str(message.content))
db["Channels"] = Channel_IDS
bot.run(".g1e5fCvWLnHBHCWoLBLhmEmWFNk")
现在的问题是,如果服务器 1 发送消息,服务器 2 接收它,但如果服务器 2 发送消息,机器人会看到该消息,但不会将其发送到服务器 1。
【问题讨论】:
标签: python discord discord.py